Debian Codegraph @

sass-spec/spec/parser/interpolate/interpolate.pl

raw
1 use strict;
2 use warnings;
3
4 use File::chdir;
5
6
7
8 my @input = (
9 ['01_literal', qq(literal)],
10 ['02_double_quoted', qq("dquoted")],
11 ['03_single_quoted', qq('squoted')],
12 ['04_space_list_quoted', qq("alpha" 'beta')],
13 ['05_comma_list_quoted', qq("alpha", 'beta')],
14 ['06_space_list_complex', qq(gamme "'"delta"'")],
15 ['07_comma_list_complex', qq(gamma, "'"delta"'")],
16 ['10_escaped_backslash', qq(\\\\)],
17 ['11_escaped_literal', qq(l\\\\ite\\ral)],
18 ['12_escaped_double_quoted', qq("l\\\\ite\\ral")],
19 ['13_escaped_single_quoted', qq('l\\\\ite\\ral')],
20
21 ['14_escapes_literal_numbers', qq(\\1\\2\\3\\4\\5\\6\\7\\8\\9)],
22 ['15_escapes_double_quoted_numbers', qq("\\1\\2\\3\\4\\5\\6\\7\\8\\9")],
23 ['16_escapes_single_quoted_numbers', qq('\\1\\2\\3\\4\\5\\6\\7\\8\\9')],
24 ['17_escapes_literal_lowercase', qq(\\b\\c\\d\\e\\f\\g\\h\\i\\j\\k\\l\\m\\n\\o\\p\\q\\r\\s\\t\\u\\v\\w\\x\\y\\z)],
25 ['18_escapes_double_quoted_lowercase', qq("\\b\\c\\d\\e\\f\\g\\h\\i\\j\\k\\l\\m\\n\\o\\p\\q\\r\\s\\t\\u\\v\\w\\x\\y\\z")],
26 ['19_escapes_single_quoted_lowercase', qq('\\b\\c\\d\\e\\f\\g\\h\\i\\j\\k\\l\\m\\n\\o\\p\\q\\r\\s\\t\\u\\v\\w\\x\\y\\z')],
27 ['20_escapes_literal_uppercase', qq(\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z)],
28 ['21_escapes_double_quoted_uppercase', qq("\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z")],
29 ['22_escapes_single_quoted_uppercase', qq('\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z')],
30
31 ['23_escapes_literal_specials', qq(\\0_\\a_\\A)],
32 ['24_escapes_double_quoted_specials', qq("\\0_\\a_\\A")],
33 ['25_escapes_single_quoted_specials', qq('\\0_\\a_\\A')],
34
35 ['26_escaped_literal_quotes', qq(\\\"\\\')],
36 ['27_escaped_double_quotes', qq("\\\"")],
37 ['28_escaped_single_quotes', qq('\\\'')],
38
39 ['29_binary_operation', qq("foo#{'ba' + 'r'}baz")],
40 ['30_base_test', qq("foo#{'ba' + 'r'}baz")],
41
42 ['31_schema_simple', qq("["'foo'"]")],
43 ['32_comma_list', qq("["',foo, '"]")],
44 ['33_space_list', qq("["'foo '"]" "bar")],
45 ['34_mixed_list', qq("["',foo , '"]" "bar")],
46
47 );
48
49 my @template;
50
51 push @template, "01_inline";
52 push @template, << "EOF";
53 .result {
54 output: %%;
55 output: #{%%};
56 output: "[#{%%}]";
57 output: "#{%%}";
58 output: '#{%%}';
59 output: "['#{%%}']";
60 }
61 EOF
62
63
64 push @template, "02_variable";
65 push @template, << "EOF";
66 \$input: %%;
67 .result {
68 output: \$input;
69 output: #{\$input};
70 output: "[#{\$input}]";
71 output: "#{\$input}";
72 output: '#{\$input}';
73 output: "['#{\$input}']";
74 }
75 EOF
76
77 push @template, "03_inline_double";
78 push @template, << "EOF";
79 .result {
80 output: #{#{%%}};
81 output: #{"[#{%%}]"};
82 output: #{"#{%%}"};
83 output: #{'#{%%}'};
84 output: #{"['#{%%}']"};
85 }
86 EOF
87
88 push @template, "04_variable_double";
89 push @template, << "EOF";
90 \$input: %%;
91 .result {
92 output: #{#{\$input}};
93 output: #{"[#{\$input}]"};
94 output: #{"#{\$input}"};
95 output: #{'#{\$input}'};
96 output: #{"['#{\$input}']"};
97 }
98 EOF
99
100 push @template, "05_variable_quoted_double";
101 push @template, << "EOF";
102 \$input: %%;
103 .result {
104 dquoted: "#{#{\$input}}";
105 dquoted: "#{"[#{\$input}]"}";
106 dquoted: "#{"#{\$input}"}";
107 dquoted: "#{'#{\$input}'}";
108 dquoted: "#{"['#{\$input}']"}";
109 squoted: '#{#{\$input}}';
110 squoted: '#{"[#{\$input}]"}';
111 squoted: '#{"#{\$input}"}';
112 squoted: '#{'#{\$input}'}';
113 squoted: '#{"['#{\$input}']"}';
114 }
115 EOF
116 # ruby sass cannot handle these cases ...
117 # pop(@template); pop(@template);
118
119 push @template, "06_escape_interpolation";
120 push @template, << "EOF";
121 \$input: %%;
122 .result {
123 output: "[\\#{%%}]";
124 output: "\\#{%%}";
125 output: '\\#{%%}';
126 output: "['\\#{%%}']";
127 }
128 EOF
129
130
131 sub render {
132 use File::Slurp qw(write_file);
133 my ($names, $template, $input) = @_;
134 $template =~ s/\%\%/$input/g;
135 local $CWD = $CWD;
136 foreach (@{$names}) {
137 mkdir $_;
138 $CWD = $_;
139 }
140 print "created ", join("/", @{$names}), "\n";
141 return write_file('input.scss', { binmode => ':raw' }, $template);
142
143 }
144
145 while (defined(my $name = shift @template)) {
146 my $template = shift(@template);
147 foreach my $input (@input) {
148 render([$input->[0], $name], $template, $input->[1]);
149 }
150 }
151
152 # <>;