Fix failing tests

This commit is contained in:
Kovid Goyal
2026-06-29 23:24:40 +05:30
parent 5bc8cfaaf5
commit bbec9d5bbd

View File

@@ -29,26 +29,26 @@ void drawTriangle(float4 pos : POSITION) {
float4 psMain() : SV_Target { float4 psMain() : SV_Target {
return float4(1, 0, 0, 1); return float4(1, 0, 0, 1);
} }
''', SlangFile('', '', frozenset(), frozenset({EntryPoint(Stage.vertex, 'drawTriangle'), EntryPoint(Stage.fragment, 'psMain')}), '')) ''', SlangFile('', '', frozenset(), frozenset({EntryPoint(Stage.vertex, 'drawTriangle'), EntryPoint(Stage.fragment, 'psMain')}), '', {}, ()))
# Empty source # Empty source
check('', SlangFile('', '', frozenset(), frozenset(), '')) check('', SlangFile('', '', frozenset(), frozenset(), '', {}, ()))
# Only line comments and block comments, no code # Only line comments and block comments, no code
check('// just a comment\n/* block comment */', SlangFile('', '', frozenset(), frozenset(), '')) check('// just a comment\n/* block comment */', SlangFile('', '', frozenset(), frozenset(), '', {}, ()))
# Module and import declarations # Module and import declarations
check(''' check('''
module mymodule; module mymodule;
import utils; import utils;
import helpers; import helpers;
''', SlangFile('', '', frozenset({'utils', 'helpers'}), frozenset(), 'mymodule')) ''', SlangFile('', '', frozenset({'utils', 'helpers'}), frozenset(), 'mymodule', {}, ()))
# pixel stage maps to Stage.fragment # pixel stage maps to Stage.fragment
check(''' check('''
[shader("pixel")] [shader("pixel")]
float4 pixelMain() : SV_Target { return float4(0); } float4 pixelMain() : SV_Target { return float4(0); }
''', SlangFile('', '', frozenset(), frozenset({EntryPoint(Stage.fragment, 'pixelMain')}), '')) ''', SlangFile('', '', frozenset(), frozenset({EntryPoint(Stage.fragment, 'pixelMain')}), '', {}, ()))
# Block comment stripping removes multi-line comments before parsing # Block comment stripping removes multi-line comments before parsing
check(''' check('''
@@ -56,7 +56,7 @@ float4 pixelMain() : SV_Target { return float4(0); }
spanning multiple lines */ spanning multiple lines */
[shader("vertex")] [shader("vertex")]
void vertMain() {} void vertMain() {}
''', SlangFile('', '', frozenset(), frozenset({EntryPoint(Stage.vertex, 'vertMain')}), '')) ''', SlangFile('', '', frozenset(), frozenset({EntryPoint(Stage.vertex, 'vertMain')}), '', {}, ()))
# Block comment containing a shader attribute must not create a false entry point # Block comment containing a shader attribute must not create a false entry point
check(''' check('''
@@ -64,7 +64,7 @@ void vertMain() {}
void shouldNotBeDetected() {} */ void shouldNotBeDetected() {} */
[shader("fragment")] [shader("fragment")]
void fragMain() {} void fragMain() {}
''', SlangFile('', '', frozenset(), frozenset({EntryPoint(Stage.fragment, 'fragMain')}), '')) ''', SlangFile('', '', frozenset(), frozenset({EntryPoint(Stage.fragment, 'fragMain')}), '', {}, ()))
# Multiple [attr] lines between [shader(...)] and the function declaration are skipped # Multiple [attr] lines between [shader(...)] and the function declaration are skipped
check(''' check('''
@@ -72,7 +72,7 @@ void fragMain() {}
[numthreads(4, 4, 1)] [numthreads(4, 4, 1)]
[SomeOtherAttribute] [SomeOtherAttribute]
float4 fragMain() : SV_Target { return float4(0); } float4 fragMain() : SV_Target { return float4(0); }
''', SlangFile('', '', frozenset(), frozenset({EntryPoint(Stage.fragment, 'fragMain')}), '')) ''', SlangFile('', '', frozenset(), frozenset({EntryPoint(Stage.fragment, 'fragMain')}), '', {}, ()))
# Multiple entry points: vertex, pixel, and fragment stages # Multiple entry points: vertex, pixel, and fragment stages
check(''' check('''
@@ -88,7 +88,7 @@ float4 fsMain() : SV_Target { return float4(0); }
EntryPoint(Stage.vertex, 'vsMain'), EntryPoint(Stage.vertex, 'vsMain'),
EntryPoint(Stage.fragment, 'psMain'), EntryPoint(Stage.fragment, 'psMain'),
EntryPoint(Stage.fragment, 'fsMain'), EntryPoint(Stage.fragment, 'fsMain'),
}), '')) }), '', {}, ()))
# module, imports and entry points together # module, imports and entry points together
check(''' check('''
@@ -97,14 +97,14 @@ import common;
[shader("vertex")] [shader("vertex")]
void vsMain() {} void vsMain() {}
''', SlangFile('', '', frozenset({'common'}), frozenset({EntryPoint(Stage.vertex, 'vsMain')}), 'myshader')) ''', SlangFile('', '', frozenset({'common'}), frozenset({EntryPoint(Stage.vertex, 'vsMain')}), 'myshader', {}, ()))
def test_slang_ordering(self): def test_slang_ordering(self):
# Test topological_sort with a manually constructed linear chain: a <- b <- c # Test topological_sort with a manually constructed linear chain: a <- b <- c
graph: dict[str, SlangFile] = { graph: dict[str, SlangFile] = {
'a': SlangFile('', '', frozenset(), frozenset(), 'a'), 'a': SlangFile('', '', frozenset(), frozenset(), 'a', {}, ()),
'b': SlangFile('', '', frozenset({'a'}), frozenset(), 'b'), 'b': SlangFile('', '', frozenset({'a'}), frozenset(), 'b', {}, ()),
'c': SlangFile('', '', frozenset({'b'}), frozenset(), 'c'), 'c': SlangFile('', '', frozenset({'b'}), frozenset(), 'c', {}, ()),
} }
order = topological_sort(graph) order = topological_sort(graph)
self.assertLess(order.index('a'), order.index('b')) self.assertLess(order.index('a'), order.index('b'))
@@ -112,10 +112,10 @@ void vsMain() {}
# Diamond dependency: base <- left, base <- right, left + right <- top # Diamond dependency: base <- left, base <- right, left + right <- top
diamond: dict[str, SlangFile] = { diamond: dict[str, SlangFile] = {
'base': SlangFile('', '', frozenset(), frozenset(), 'base'), 'base': SlangFile('', '', frozenset(), frozenset(), 'base', {}, ()),
'left': SlangFile('', '', frozenset({'base'}), frozenset(), 'left'), 'left': SlangFile('', '', frozenset({'base'}), frozenset(), 'left', {}, ()),
'right': SlangFile('', '', frozenset({'base'}), frozenset(), 'right'), 'right': SlangFile('', '', frozenset({'base'}), frozenset(), 'right', {}, ()),
'top': SlangFile('', '', frozenset({'left', 'right'}), frozenset(), 'top'), 'top': SlangFile('', '', frozenset({'left', 'right'}), frozenset(), 'top', {}, ()),
} }
order2 = topological_sort(diamond) order2 = topological_sort(diamond)
self.assertLess(order2.index('base'), order2.index('left')) self.assertLess(order2.index('base'), order2.index('left'))
@@ -125,7 +125,7 @@ void vsMain() {}
# Node with an import not present in the graph is silently skipped # Node with an import not present in the graph is silently skipped
partial: dict[str, SlangFile] = { partial: dict[str, SlangFile] = {
'x': SlangFile('', '', frozenset({'missing'}), frozenset(), 'x'), 'x': SlangFile('', '', frozenset({'missing'}), frozenset(), 'x', {}, ()),
} }
self.assertEqual(topological_sort(partial), ['x']) self.assertEqual(topological_sort(partial), ['x'])