22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ #include < initializer_list>
6+ #include < vector>
7+
58#include " flutter/fml/command_line.h"
69#include " flutter/fml/file.h"
710#include " flutter/testing/testing.h"
@@ -12,6 +15,19 @@ namespace impeller {
1215namespace compiler {
1316namespace testing {
1417
18+ Switches MakeSwitchesDesktopGL (
19+ std::initializer_list<const char *> additional_options = {}) {
20+ std::vector<const char *> options = {" --opengl-desktop" , " --input=input.vert" ,
21+ " --sl=output.vert" ,
22+ " --spirv=output.spirv" };
23+ options.insert (options.end (), additional_options.begin (),
24+ additional_options.end ());
25+
26+ auto cl = fml::CommandLineFromIteratorsWithArgv0 (" impellerc" , options.begin (),
27+ options.end ());
28+ return Switches (cl);
29+ }
30+
1531TEST (SwitchesTest, DoesntMangleUnicodeIncludes) {
1632 const char * directory_name = " test_shader_include_�" ;
1733 fml::CreateDirectory (flutter::testing::OpenFixturesDirectory (),
@@ -21,16 +37,26 @@ TEST(SwitchesTest, DoesntMangleUnicodeIncludes) {
2137 std::string (flutter::testing::GetFixturesPath ()) + " /" + directory_name;
2238 auto include_option = " --include=" + include_path;
2339
24- const auto cl = fml::CommandLineFromInitializerList (
25- {" impellerc" , " --opengl-desktop" , " --input=input.vert" ,
26- " --sl=output.vert" , " --spirv=output.spirv" , include_option.c_str ()});
27- Switches switches (cl);
40+ Switches switches = MakeSwitchesDesktopGL ({include_option.c_str ()});
41+
2842 ASSERT_TRUE (switches.AreValid (std::cout));
2943 ASSERT_EQ (switches.include_directories .size (), 1u );
3044 ASSERT_NE (switches.include_directories [0 ].dir , nullptr );
3145 ASSERT_EQ (switches.include_directories [0 ].name , include_path);
3246}
3347
48+ TEST (SwitchesTest, SourceLanguageDefaultsToGLSL) {
49+ Switches switches = MakeSwitchesDesktopGL ();
50+ ASSERT_TRUE (switches.AreValid (std::cout));
51+ ASSERT_EQ (switches.source_language , SourceLanguage::kGLSL );
52+ }
53+
54+ TEST (SwitchesTest, SourceLanguageCanBeSetToHLSL) {
55+ Switches switches = MakeSwitchesDesktopGL ({" --source-language=hLsL" });
56+ ASSERT_TRUE (switches.AreValid (std::cout));
57+ ASSERT_EQ (switches.source_language , SourceLanguage::kHLSL );
58+ }
59+
3460} // namespace testing
3561} // namespace compiler
3662} // namespace impeller
0 commit comments