1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
require 'spec_helper'
require 'puppet/pops'
# relative to this spec file (./) does not work as this file is loaded by rspec
require File.join(File.dirname(__FILE__), '/parser_rspec_helper')
describe "egrammar parsing heredoc" do
include ParserRspecHelper
it "parses plain heredoc" do
dump(parse("@(END)\nThis is\nheredoc text\nEND\n")).should == [
"(@()",
" (sublocated 'This is\nheredoc text\n')",
")"
].join("\n")
end
it "parses heredoc with margin" do
src = [
"@(END)",
" This is",
" heredoc text",
" | END",
""
].join("\n")
dump(parse(src)).should == [
"(@()",
" (sublocated 'This is\nheredoc text\n')",
")"
].join("\n")
end
it "parses heredoc with margin and right newline trim" do
src = [
"@(END)",
" This is",
" heredoc text",
" |- END",
""
].join("\n")
dump(parse(src)).should == [
"(@()",
" (sublocated 'This is\nheredoc text')",
")"
].join("\n")
end
it "parses syntax and escape specification" do
src = <<-CODE
@(END:syntax/t)
Tex\\tt\\n
|- END
CODE
dump(parse(src)).should == [
"(@(syntax)",
" (sublocated 'Tex\tt\\n')",
")"
].join("\n")
end
it "parses interpolated heredoc expression" do
src = <<-CODE
@("END")
Hello $name
|- END
CODE
dump(parse(src)).should == [
"(@()",
" (sublocated (cat 'Hello ' (str $name) ''))",
")"
].join("\n")
end
it "parses interpolated heredoc expression with false start on $" do
src = <<-CODE
@("END")
Hello $name$%a
|- END
CODE
dump(parse(src)).should == [
"(@()",
" (sublocated (cat 'Hello ' (str $name) '$%a'))",
")"
].join("\n")
end
end
|