File: testHereDocument.rb

package info (click to toggle)
jruby 1.5.6-9
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 45,088 kB
  • ctags: 77,093
  • sloc: ruby: 398,491; java: 170,202; yacc: 3,782; xml: 2,529; sh: 299; tcl: 40; makefile: 35; ansic: 23
file content (95 lines) | stat: -rw-r--r-- 1,660 bytes parent folder | download | duplicates (4)
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
88
89
90
91
92
93
94
95
require 'test/minirunit'

test_check "Test here document:"

# Multiple Heredocs as arguments
multiDoc = <<-STRING1, <<-STRING2
   Concat
   STRING1
      enate
      STRING2

test_equal(["   Concat\n","      enate\n"], multiDoc)

# Should retain extra newlines at end of heredocs
str = <<-EOL
blah-blah


EOL

test_equal("blah-blah\n\n\n",str)

# - (indent) operation should result in same string
# as non-indented version
str1 = <<EOL
baw-waw


EOL

str2 = <<-EOL
baw-waw


              EOL
              
test_equal(str1, str2)

$global = "global value"
s =<<EOT
#$global
EOT
test_equal($global + "\n", s)

value = "some value"
value.sub!(/\A(\S*)(.*?)(\S*)\Z/m) do |m|
  <<EOT
#$global
EOT
end
test_equal($global + "\n", value)

value = "some value"
value.sub!(/\A(\S*)(.*?)(\S*)\Z/m) do |m|
  <<EOT
#{$1} other #{$3}
EOT
end
test_equal("some other value\n", value)

value = "some value"
value.sub!(/\A(\S*)(.*?)(\S*)\Z/m) do |m|
  <<EOT
#$1 other #$3
EOT
end
test_equal("some other value\n", value)

value = "some value"
value.sub!(/\A(\S*)(.*?)(\S*)\Z/m) do |m|
  <<"EOT"
#{$1} other #{$3}
EOT
end
test_equal("some other value\n", value)

value = "some value"
value.sub!(/\A(\S*)(.*?)(\S*)\Z/m) do |m|
  <<'EOT'
#$1 other #$3
EOT
end
test_equal('#$1 other #$3', value.chomp)

data_file = File.expand_path(File.join(File.dirname(__FILE__), 'heredoc_CRLF_data.rb'))
load(data_file)
test_equal("  Multiline\n  text\n", $HEREDOC)

test_equal("  Line1\n  Line2\n", $HEREDOC_WITH_INDENT)

# Note: This test must be last test of this file and the EOF beneath it must
# not end in a newline.  Test HEREDOC terminating without newline.
str = <<EOF
 some text
EOF