aboutsummaryrefslogtreecommitdiffstats
path: root/test/testdata/eval-okay-ind-string.nix
diff options
context:
space:
mode:
Diffstat (limited to 'test/testdata/eval-okay-ind-string.nix')
-rw-r--r--test/testdata/eval-okay-ind-string.nix128
1 files changed, 128 insertions, 0 deletions
diff --git a/test/testdata/eval-okay-ind-string.nix b/test/testdata/eval-okay-ind-string.nix
new file mode 100644
index 0000000..95d59b5
--- /dev/null
+++ b/test/testdata/eval-okay-ind-string.nix
@@ -0,0 +1,128 @@
1let
2
3 s1 = ''
4 This is an indented multi-line string
5 literal. An amount of whitespace at
6 the start of each line matching the minimum
7 indentation of all lines in the string
8 literal together will be removed. Thus,
9 in this case four spaces will be
10 stripped from each line, even though
11 THIS LINE is indented six spaces.
12
13 Also, empty lines don't count in the
14 determination of the indentation level (the
15 previous empty line has indentation 0, but
16 it doesn't matter).
17 '';
18
19 s2 = '' If the string starts with whitespace
20 followed by a newline, it's stripped, but
21 that's not the case here. Two spaces are
22 stripped because of the " " at the start.
23 '';
24
25 s3 = ''
26 This line is indented
27 a bit further.
28 ''; # indentation of last line doesn't count if it's empty
29
30 s4 = ''
31 Anti-quotations, like ${if true then "so" else "not so"}, are
32 also allowed.
33 '';
34
35 s5 = ''
36 The \ is not special here.
37 ' can be followed by any character except another ', e.g. 'x'.
38 Likewise for $, e.g. $$ or $varName.
39 But ' followed by ' is special, as is $ followed by {.
40 If you want them, use anti-quotations: ${"''"}, ${"\${"}.
41 '';
42
43 s6 = ''
44 Tabs are not interpreted as whitespace (since we can't guess
45 what tab settings are intended), so don't use them.
46 This line starts with a space and a tab, so only one
47 space will be stripped from each line.
48 '';
49
50 s7 = ''
51 Also note that if the last line (just before the closing ' ')
52 consists only of whitespace, it's ignored. But here there is
53 some non-whitespace stuff, so the line isn't removed. '';
54
55 s8 = '' ${""}
56 This shows a hacky way to preserve an empty line after the start.
57 But there's no reason to do so: you could just repeat the empty
58 line.
59 '';
60
61 s9 = ''
62 ${""} Similarly you can force an indentation level,
63 in this case to 2 spaces. This works because the anti-quote
64 is significant (not whitespace).
65 '';
66
67 s10 = ''
68 '';
69
70 s11 = '''';
71
72 s12 = '' '';
73
74 s13 = ''
75 start on network-interfaces
76
77 start script
78
79 rm -f /var/run/opengl-driver
80 ${if true
81 then "ln -sf 123 /var/run/opengl-driver"
82 else if true
83 then "ln -sf 456 /var/run/opengl-driver"
84 else ""
85 }
86
87 rm -f /var/log/slim.log
88
89 end script
90
91 env SLIM_CFGFILE=${"abc"}
92 env SLIM_THEMESDIR=${"def"}
93 env FONTCONFIG_FILE=/etc/fonts/fonts.conf # !!! cleanup
94 env XKB_BINDIR=${"foo"}/bin # Needed for the Xkb extension.
95 env LD_LIBRARY_PATH=${"libX11"}/lib:${"libXext"}/lib:/usr/lib/ # related to xorg-sys-opengl - needed to load libglx for (AI)GLX support (for compiz)
96
97 ${if true
98 then "env XORG_DRI_DRIVER_PATH=${"nvidiaDrivers"}/X11R6/lib/modules/drivers/"
99 else if true
100 then "env XORG_DRI_DRIVER_PATH=${"mesa"}/lib/modules/dri"
101 else ""
102 }
103
104 exec ${"slim"}/bin/slim
105 '';
106
107 s14 = ''
108 Escaping of ' followed by ': '''
109 Escaping of $ followed by {: ''${
110 And finally to interpret \n etc. as in a string: ''\n, ''\r, ''\t.
111 '';
112
113 # Regression test: string interpolation in '${x}' should work, but didn't.
114 s15 = let x = "bla"; in ''
115 foo
116 '${x}'
117 bar
118 '';
119
120 # Regression test: accept $'.
121 s16 = ''
122 cut -d $'\t' -f 1
123 '';
124
125 # Accept dollars at end of strings
126 s17 = ''ending dollar $'' + ''$'' + "\n";
127
128in s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10 + s11 + s12 + s13 + s14 + s15 + s16 + s17