Skip to content

Commit

Permalink
Merge branch 'preprocessor' of https://github.com/himaanisrivatsava/c…
Browse files Browse the repository at this point in the history
…rosstl into preprocessor
  • Loading branch information
himaanisrivatsava committed Jan 5, 2025
2 parents d81c378 + c218488 commit 555b23e
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions tests/test_backend/test_directx/test_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from crosstl.backend.DirectX.DirectxParser import HLSLParser
from crosstl.backend.DirectX.DirectxCrossGLCodeGen import HLSLToCrossGLConverter


class TestHLSLPreprocessor:
def setup_method(self):

Expand All @@ -21,10 +22,10 @@ def test_include_directive(self):
assert "// Included file: common.hlsl" in output

def test_define_directive(self):
shader_code = '#define MAX_LIGHTS 10\nfloat4 main() : SV_Target { return MAX_LIGHTS; }'
expected_output = (
"float4 main() : SV_Target { return 10; }"
shader_code = (
"#define MAX_LIGHTS 10\nfloat4 main() : SV_Target { return MAX_LIGHTS; }"
)
expected_output = "float4 main() : SV_Target { return 10; }"
lexer = HLSLLexer(shader_code)
tokens = lexer.tokenize()
parser = HLSLParser(tokens)
Expand All @@ -33,10 +34,8 @@ def test_define_directive(self):
assert "float4 main() : SV_Target { return 10; }" in output

def test_ifdef_directive(self):
shader_code = '#ifdef MAX_LIGHTS\nfloat4 main() : SV_Target { return MAX_LIGHTS; }\n#endif'
expected_output = (
"float4 main() : SV_Target { return MAX_LIGHTS; }"
)
shader_code = "#ifdef MAX_LIGHTS\nfloat4 main() : SV_Target { return MAX_LIGHTS; }\n#endif"
expected_output = "float4 main() : SV_Target { return MAX_LIGHTS; }"
lexer = HLSLLexer(shader_code)
tokens = lexer.tokenize()
parser = HLSLParser(tokens)
Expand All @@ -45,14 +44,12 @@ def test_ifdef_directive(self):
assert "float4 main() : SV_Target { return MAX_LIGHTS; }" in output

def test_else_directive(self):
shader_code = '''#ifdef MAX_LIGHTS
shader_code = """#ifdef MAX_LIGHTS
float4 main() : SV_Target { return MAX_LIGHTS; }
#else
float4 main() : SV_Target { return 0; }
#endif'''
expected_output = (
"float4 main() : SV_Target { return MAX_LIGHTS; }"
)
#endif"""
expected_output = "float4 main() : SV_Target { return MAX_LIGHTS; }"
lexer = HLSLLexer(shader_code)
tokens = lexer.tokenize()
parser = HLSLParser(tokens)
Expand All @@ -61,12 +58,10 @@ def test_else_directive(self):
assert "float4 main() : SV_Target { return MAX_LIGHTS; }" in output

def test_endif_directive(self):
shader_code = '''#ifdef MAX_LIGHTS
shader_code = """#ifdef MAX_LIGHTS
float4 main() : SV_Target { return MAX_LIGHTS; }
#endif'''
expected_output = (
"float4 main() : SV_Target { return MAX_LIGHTS; }"
)
#endif"""
expected_output = "float4 main() : SV_Target { return MAX_LIGHTS; }"
lexer = HLSLLexer(shader_code)
tokens = lexer.tokenize()
parser = HLSLParser(tokens)
Expand All @@ -76,4 +71,4 @@ def test_endif_directive(self):


if __name__ == "__main__":
pytest.main()
pytest.main()

0 comments on commit 555b23e

Please sign in to comment.