puppet-lint 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -209,7 +209,7 @@ describe PuppetLint::Bin do
209
209
 
210
210
  its(:exitstatus) { is_expected.to eq(1) }
211
211
  its(:stdout) {
212
- is_expected.to match(%r{^/.+/spec/fixtures/test/manifests/fail\.pp$})
212
+ is_expected.to match(%r{^(/|[A-Za-z]\:).+/spec/fixtures/test/manifests/fail\.pp$})
213
213
  }
214
214
  end
215
215
 
@@ -336,4 +336,12 @@ describe PuppetLint::Bin do
336
336
  its(:exitstatus) { is_expected.to eq(0) }
337
337
  its(:stdout) { is_expected.to match(/WARNING: lint:endignore comment with no opening lint:ignore:<check> comment found on line 1/) }
338
338
  end
339
+
340
+ context 'when a lint:ignore control comment block is not terminated properly' do
341
+ let(:args) { [
342
+ 'spec/fixtures/test/manifests/unterminated_control_comment.pp',
343
+ ] }
344
+
345
+ its(:stdout) { is_expected.to match(/WARNING: lint:ignore:140chars comment on line 2 with no closing lint:endignore comment/) }
346
+ end
339
347
  end
@@ -13,51 +13,51 @@ describe PuppetLint::Lexer do
13
13
 
14
14
  context '#new_token' do
15
15
  it 'should calculate the line number for an empty string' do
16
- token = @lexer.new_token(:TEST, 'test', 4)
16
+ token = @lexer.new_token(:TEST, 'test')
17
17
  expect(token.line).to eq(1)
18
18
  end
19
19
 
20
20
  it 'should get correct line number after double quoted multi line string' do
21
- token = @lexer.new_token(:STRING, "test\ntest", 9)
22
- token = @lexer.new_token(:TEST, 'test', 4)
21
+ token = @lexer.new_token(:STRING, "test\ntest")
22
+ token = @lexer.new_token(:TEST, 'test')
23
23
  expect(token.line).to eq(2)
24
24
  end
25
25
 
26
26
  it 'should get correct line number after a multi line comment' do
27
- token = @lexer.new_token(:MLCOMMENT, "test\ntest", 9)
28
- token = @lexer.new_token(:TEST, 'test', 4)
27
+ token = @lexer.new_token(:MLCOMMENT, "test\ntest", :raw => "/*test\ntest*/")
28
+ token = @lexer.new_token(:TEST, 'test')
29
29
  expect(token.line).to eq(2)
30
30
  end
31
31
 
32
32
  it 'should calculate the line number for a multi line string' do
33
- token = @lexer.new_token(:SSTRING, "test\ntest", 9)
34
- token = @lexer.new_token(:TEST, 'test', 4)
33
+ token = @lexer.new_token(:SSTRING, "test\ntest")
34
+ token = @lexer.new_token(:TEST, 'test')
35
35
  expect(token.line).to eq(2)
36
36
  end
37
37
 
38
38
  it 'should calculate line number for string that ends with newline' do
39
- token = @lexer.new_token(:SSTRING, "test\n", 5)
40
- token = @lexer.new_token(:TEST, 'test', 4)
39
+ token = @lexer.new_token(:SSTRING, "test\n")
40
+ token = @lexer.new_token(:TEST, 'test')
41
41
  expect(token.line).to eq(2)
42
42
  end
43
43
 
44
44
  it 'should calculate the column number for an empty string' do
45
- token = @lexer.new_token(:TEST, 'test', 4)
45
+ token = @lexer.new_token(:TEST, 'test')
46
46
  expect(token.column).to eq(1)
47
47
  end
48
48
 
49
49
  it 'should calculate the column number for a single line string' do
50
- @lexer.instance_variable_set('@column', 'this is a test'.size)
51
- token = @lexer.new_token(:TEST, 'test', 4)
52
- expect(token.column).to eq(14)
50
+ @lexer.new_token(:SSTRING, 'this is a test')
51
+ token = @lexer.new_token(:TEST, 'test')
52
+ expect(token.column).to eq(17)
53
53
  end
54
54
 
55
55
  it 'should calculate the column number for a multi line string' do
56
56
  @lexer.instance_variable_set('@line_no', 4)
57
- @lexer.instance_variable_set('@column', "gronk".size)
58
- token = @lexer.new_token(:SSTRING, "test\ntest", 9)
59
- token = @lexer.new_token(:TEST, 'test', 4)
60
- expect(token.column).to eq(4)
57
+ @lexer.instance_variable_set('@column', 5)
58
+ token = @lexer.new_token(:SSTRING, "test\ntest")
59
+ token = @lexer.new_token(:TEST, 'test')
60
+ expect(token.column).to eq(6)
61
61
  end
62
62
  end
63
63
 
@@ -198,6 +198,7 @@ describe PuppetLint::Lexer do
198
198
  expect(tokens[1].value).to eq('bar')
199
199
  expect(tokens[1].line).to eq(1)
200
200
  expect(tokens[1].column).to eq(3)
201
+ expect(tokens[1].to_manifest).to eq("${bar}")
201
202
 
202
203
  expect(tokens[2].type).to eq(:DQPOST)
203
204
  expect(tokens[2].value).to eq('')
@@ -205,6 +206,29 @@ describe PuppetLint::Lexer do
205
206
  expect(tokens[2].column).to eq(8)
206
207
  end
207
208
 
209
+ it 'should not remove the unnecessary $ from enclosed variables' do
210
+ tokens = @lexer.tokenise('"${$bar}"')
211
+
212
+ expect(tokens.length).to eq(3)
213
+
214
+ expect(tokens[0].type).to eq(:DQPRE)
215
+ expect(tokens[0].value).to eq('')
216
+ expect(tokens[0].line).to eq(1)
217
+ expect(tokens[0].column).to eq(1)
218
+
219
+ expect(tokens[1].type).to eq(:VARIABLE)
220
+ expect(tokens[1].value).to eq('bar')
221
+ expect(tokens[1].raw).to eq('$bar')
222
+ expect(tokens[1].line).to eq(1)
223
+ expect(tokens[1].column).to eq(4)
224
+ expect(tokens[1].to_manifest).to eq("${$bar}")
225
+
226
+ expect(tokens[2].type).to eq(:DQPOST)
227
+ expect(tokens[2].value).to eq('')
228
+ expect(tokens[2].line).to eq(1)
229
+ expect(tokens[2].column).to eq(9)
230
+ end
231
+
208
232
  it 'should handle a variable with an array reference' do
209
233
  @lexer.interpolate_string('${foo[bar][baz]}"', 1, 1)
210
234
  tokens = @lexer.tokens
@@ -630,6 +654,342 @@ describe PuppetLint::Lexer do
630
654
  end
631
655
  end
632
656
 
657
+ context ':HEREDOC without interpolation' do
658
+ it 'should parse a simple heredoc' do
659
+ manifest = <<-END.gsub(/^ {6}/, '')
660
+ $str = @(myheredoc)
661
+ SOMETHING
662
+ ELSE
663
+ :
664
+ |-myheredoc
665
+ END
666
+ tokens = @lexer.tokenise(manifest)
667
+
668
+ expect(tokens.length).to eq(8)
669
+ expect(tokens[0].type).to eq(:VARIABLE)
670
+ expect(tokens[0].value).to eq("str")
671
+ expect(tokens[0].line).to eq(1)
672
+ expect(tokens[0].column).to eq(1)
673
+ expect(tokens[1].type).to eq(:WHITESPACE)
674
+ expect(tokens[1].value).to eq(' ')
675
+ expect(tokens[1].line).to eq(1)
676
+ expect(tokens[1].column).to eq(5)
677
+ expect(tokens[2].type).to eq(:EQUALS)
678
+ expect(tokens[2].value).to eq('=')
679
+ expect(tokens[2].line).to eq(1)
680
+ expect(tokens[2].column).to eq(6)
681
+ expect(tokens[3].type).to eq(:WHITESPACE)
682
+ expect(tokens[3].value).to eq(' ')
683
+ expect(tokens[3].line).to eq(1)
684
+ expect(tokens[3].column).to eq(7)
685
+ expect(tokens[4].type).to eq(:HEREDOC_OPEN)
686
+ expect(tokens[4].value).to eq('myheredoc')
687
+ expect(tokens[4].line).to eq(1)
688
+ expect(tokens[4].column).to eq(8)
689
+ expect(tokens[5].type).to eq(:NEWLINE)
690
+ expect(tokens[5].value).to eq("\n")
691
+ expect(tokens[5].line).to eq(1)
692
+ expect(tokens[5].column).to eq(20)
693
+ expect(tokens[6].type).to eq(:HEREDOC)
694
+ expect(tokens[6].value).to eq(" SOMETHING\n ELSE\n :\n ")
695
+ expect(tokens[6].raw).to eq(" SOMETHING\n ELSE\n :\n |-myheredoc")
696
+ expect(tokens[6].line).to eq(2)
697
+ expect(tokens[6].column).to eq(1)
698
+ expect(tokens[7].type).to eq(:NEWLINE)
699
+ expect(tokens[7].line).to eq(5)
700
+ expect(tokens[7].column).to eq(14)
701
+ end
702
+
703
+ it 'should not interpolate the contents of the heredoc' do
704
+ manifest = <<-END.gsub(/^ {6}/, '')
705
+ $str = @(myheredoc)
706
+ SOMETHING
707
+ ${else}
708
+ :
709
+ |-myheredoc
710
+ END
711
+ tokens = @lexer.tokenise(manifest)
712
+
713
+ expect(tokens.length).to eq(8)
714
+ expect(tokens[0].type).to eq(:VARIABLE)
715
+ expect(tokens[0].value).to eq('str')
716
+ expect(tokens[0].line).to eq(1)
717
+ expect(tokens[0].column).to eq(1)
718
+ expect(tokens[1].type).to eq(:WHITESPACE)
719
+ expect(tokens[1].value).to eq(' ')
720
+ expect(tokens[1].line).to eq(1)
721
+ expect(tokens[1].column).to eq(5)
722
+ expect(tokens[2].type).to eq(:EQUALS)
723
+ expect(tokens[2].value).to eq('=')
724
+ expect(tokens[2].line).to eq(1)
725
+ expect(tokens[2].column).to eq(6)
726
+ expect(tokens[3].type).to eq(:WHITESPACE)
727
+ expect(tokens[3].value).to eq(' ')
728
+ expect(tokens[3].line).to eq(1)
729
+ expect(tokens[3].column).to eq(7)
730
+ expect(tokens[4].type).to eq(:HEREDOC_OPEN)
731
+ expect(tokens[4].value).to eq('myheredoc')
732
+ expect(tokens[4].line).to eq(1)
733
+ expect(tokens[4].column).to eq(8)
734
+ expect(tokens[5].type).to eq(:NEWLINE)
735
+ expect(tokens[5].value).to eq("\n")
736
+ expect(tokens[5].line).to eq(1)
737
+ expect(tokens[5].column).to eq(20)
738
+ expect(tokens[6].type).to eq(:HEREDOC)
739
+ expect(tokens[6].value).to eq(" SOMETHING\n ${else}\n :\n ")
740
+ expect(tokens[6].raw).to eq(" SOMETHING\n ${else}\n :\n |-myheredoc")
741
+ expect(tokens[6].line).to eq(2)
742
+ expect(tokens[6].column).to eq(1)
743
+ expect(tokens[7].type).to eq(:NEWLINE)
744
+ expect(tokens[7].value).to eq("\n")
745
+ expect(tokens[7].line).to eq(5)
746
+ expect(tokens[7].column).to eq(14)
747
+ end
748
+
749
+ it 'should handle multiple heredoc declarations on a single line' do
750
+ manifest = <<-END.gsub(/^ {6}/, '')
751
+ $str = "${@(end1)} ${@(end2)}"
752
+ foo
753
+ |-end1
754
+ bar
755
+ |-end2
756
+ END
757
+ tokens = @lexer.tokenise(manifest)
758
+
759
+ expect(tokens.length).to eq(14)
760
+ expect(tokens[0].type).to eq(:VARIABLE)
761
+ expect(tokens[0].value).to eq('str')
762
+ expect(tokens[0].line).to eq(1)
763
+ expect(tokens[0].column).to eq(1)
764
+ expect(tokens[1].type).to eq(:WHITESPACE)
765
+ expect(tokens[1].value).to eq(' ')
766
+ expect(tokens[1].line).to eq(1)
767
+ expect(tokens[1].column).to eq(5)
768
+ expect(tokens[2].type).to eq(:EQUALS)
769
+ expect(tokens[2].value).to eq('=')
770
+ expect(tokens[2].line).to eq(1)
771
+ expect(tokens[2].column).to eq(6)
772
+ expect(tokens[3].type).to eq(:WHITESPACE)
773
+ expect(tokens[3].value).to eq(' ')
774
+ expect(tokens[3].line).to eq(1)
775
+ expect(tokens[3].column).to eq(7)
776
+ expect(tokens[4].type).to eq(:DQPRE)
777
+ expect(tokens[4].value).to eq('')
778
+ expect(tokens[4].line).to eq(1)
779
+ expect(tokens[4].column).to eq(8)
780
+ expect(tokens[5].type).to eq(:HEREDOC_OPEN)
781
+ expect(tokens[5].value).to eq('end1')
782
+ expect(tokens[5].line).to eq(1)
783
+ expect(tokens[5].column).to eq(11)
784
+ expect(tokens[6].type).to eq(:DQMID)
785
+ expect(tokens[6].value).to eq(' ')
786
+ expect(tokens[6].line).to eq(1)
787
+ expect(tokens[6].column).to eq(19)
788
+ expect(tokens[7].type).to eq(:HEREDOC_OPEN)
789
+ expect(tokens[7].value).to eq('end2')
790
+ expect(tokens[7].line).to eq(1)
791
+ expect(tokens[7].column).to eq(22)
792
+ expect(tokens[8].type).to eq(:DQPOST)
793
+ expect(tokens[8].value).to eq('')
794
+ expect(tokens[8].line).to eq(1)
795
+ expect(tokens[8].column).to eq(30)
796
+ expect(tokens[9].type).to eq(:NEWLINE)
797
+ expect(tokens[9].value).to eq("\n")
798
+ expect(tokens[9].line).to eq(1)
799
+ expect(tokens[9].column).to eq(31)
800
+ expect(tokens[10].type).to eq(:HEREDOC)
801
+ expect(tokens[10].value).to eq(" foo\n ")
802
+ expect(tokens[10].raw).to eq(" foo\n |-end1")
803
+ expect(tokens[10].line).to eq(2)
804
+ expect(tokens[10].column).to eq(1)
805
+ expect(tokens[11].type).to eq(:NEWLINE)
806
+ expect(tokens[11].value).to eq("\n")
807
+ expect(tokens[11].line).to eq(3)
808
+ expect(tokens[11].column).to eq(9)
809
+ expect(tokens[12].type).to eq(:HEREDOC)
810
+ expect(tokens[12].value).to eq(" bar\n ")
811
+ expect(tokens[12].raw).to eq(" bar\n |-end2")
812
+ expect(tokens[12].line).to eq(4)
813
+ expect(tokens[12].column).to eq(1)
814
+ expect(tokens[13].type).to eq(:NEWLINE)
815
+ expect(tokens[13].value).to eq("\n")
816
+ expect(tokens[13].line).to eq(5)
817
+ expect(tokens[13].column).to eq(9)
818
+ end
819
+
820
+ it 'should handle a heredoc that specifies a syntax' do
821
+ manifest = <<-END.gsub(/^ {6}/, '')
822
+ $str = @("end":json/)
823
+ {
824
+ "foo": "bar"
825
+ }
826
+ |-end
827
+ END
828
+
829
+ tokens = @lexer.tokenise(manifest)
830
+
831
+ expect(tokens.length).to eq(8)
832
+ expect(tokens[0].type).to eq(:VARIABLE)
833
+ expect(tokens[0].value).to eq("str")
834
+ expect(tokens[0].line).to eq(1)
835
+ expect(tokens[0].column).to eq(1)
836
+ expect(tokens[1].type).to eq(:WHITESPACE)
837
+ expect(tokens[1].value).to eq(' ')
838
+ expect(tokens[1].line).to eq(1)
839
+ expect(tokens[1].column).to eq(5)
840
+ expect(tokens[2].type).to eq(:EQUALS)
841
+ expect(tokens[2].value).to eq('=')
842
+ expect(tokens[2].line).to eq(1)
843
+ expect(tokens[2].column).to eq(6)
844
+ expect(tokens[3].type).to eq(:WHITESPACE)
845
+ expect(tokens[3].value).to eq(' ')
846
+ expect(tokens[3].line).to eq(1)
847
+ expect(tokens[3].column).to eq(7)
848
+ expect(tokens[4].type).to eq(:HEREDOC_OPEN)
849
+ expect(tokens[4].value).to eq('"end":json/')
850
+ expect(tokens[4].line).to eq(1)
851
+ expect(tokens[4].column).to eq(8)
852
+ expect(tokens[5].type).to eq(:NEWLINE)
853
+ expect(tokens[5].value).to eq("\n")
854
+ expect(tokens[5].line).to eq(1)
855
+ expect(tokens[5].column).to eq(22)
856
+ expect(tokens[6].type).to eq(:HEREDOC)
857
+ expect(tokens[6].value).to eq(" {\n \"foo\": \"bar\"\n }\n ")
858
+ expect(tokens[6].raw).to eq(" {\n \"foo\": \"bar\"\n }\n |-end")
859
+ expect(tokens[6].line).to eq(2)
860
+ expect(tokens[6].column).to eq(1)
861
+ expect(tokens[7].type).to eq(:NEWLINE)
862
+ expect(tokens[7].value).to eq("\n")
863
+ expect(tokens[7].line).to eq(5)
864
+ expect(tokens[7].column).to eq(8)
865
+ end
866
+ end
867
+
868
+ context ':HEREDOC with interpolation' do
869
+ it 'should parse a heredoc with no interpolated values as a :HEREDOC' do
870
+ manifest = <<-END.gsub(/^ {6}/, '')
871
+ $str = @("myheredoc"/)
872
+ SOMETHING
873
+ ELSE
874
+ :
875
+ |-myheredoc
876
+ END
877
+ tokens = @lexer.tokenise(manifest)
878
+
879
+ expect(tokens[0].type).to eq(:VARIABLE)
880
+ expect(tokens[0].value).to eq("str")
881
+ expect(tokens[0].line).to eq(1)
882
+ expect(tokens[0].column).to eq(1)
883
+ expect(tokens[1].type).to eq(:WHITESPACE)
884
+ expect(tokens[1].value).to eq(' ')
885
+ expect(tokens[1].line).to eq(1)
886
+ expect(tokens[1].column).to eq(5)
887
+ expect(tokens[2].type).to eq(:EQUALS)
888
+ expect(tokens[2].value).to eq('=')
889
+ expect(tokens[2].line).to eq(1)
890
+ expect(tokens[2].column).to eq(6)
891
+ expect(tokens[3].type).to eq(:WHITESPACE)
892
+ expect(tokens[3].value).to eq(' ')
893
+ expect(tokens[3].line).to eq(1)
894
+ expect(tokens[3].column).to eq(7)
895
+ expect(tokens[4].type).to eq(:HEREDOC_OPEN)
896
+ expect(tokens[4].value).to eq('"myheredoc"/')
897
+ expect(tokens[4].line).to eq(1)
898
+ expect(tokens[4].column).to eq(8)
899
+ expect(tokens[5].type).to eq(:NEWLINE)
900
+ expect(tokens[5].value).to eq("\n")
901
+ expect(tokens[5].line).to eq(1)
902
+ expect(tokens[5].column).to eq(23)
903
+ expect(tokens[6].type).to eq(:HEREDOC)
904
+ expect(tokens[6].value).to eq(" SOMETHING\n ELSE\n :\n ")
905
+ expect(tokens[6].raw).to eq(" SOMETHING\n ELSE\n :\n |-myheredoc")
906
+ expect(tokens[6].line).to eq(2)
907
+ expect(tokens[6].column).to eq(1)
908
+ expect(tokens[7].type).to eq(:NEWLINE)
909
+ expect(tokens[7].value).to eq("\n")
910
+ expect(tokens[7].line).to eq(5)
911
+ expect(tokens[7].column).to eq(14)
912
+ end
913
+
914
+ it 'should parse a heredoc with interpolated values' do
915
+ manifest = <<-END.gsub(/^ {6}/, '')
916
+ $str = @("myheredoc"/)
917
+ SOMETHING
918
+ ${else}
919
+ AND :
920
+ $another
921
+ THING
922
+ | myheredoc
923
+ END
924
+
925
+ tokens = @lexer.tokenise(manifest)
926
+
927
+ expect(tokens[0].type).to eq(:VARIABLE)
928
+ expect(tokens[0].value).to eq('str')
929
+ expect(tokens[0].line).to eq(1)
930
+ expect(tokens[0].column).to eq(1)
931
+ expect(tokens[1].type).to eq(:WHITESPACE)
932
+ expect(tokens[1].value).to eq(' ')
933
+ expect(tokens[1].line).to eq(1)
934
+ expect(tokens[1].column).to eq(5)
935
+ expect(tokens[2].type).to eq(:EQUALS)
936
+ expect(tokens[2].value).to eq('=')
937
+ expect(tokens[2].line).to eq(1)
938
+ expect(tokens[2].column).to eq(6)
939
+ expect(tokens[3].type).to eq(:WHITESPACE)
940
+ expect(tokens[3].value).to eq(' ')
941
+ expect(tokens[3].line).to eq(1)
942
+ expect(tokens[3].column).to eq(7)
943
+ expect(tokens[4].type).to eq(:HEREDOC_OPEN)
944
+ expect(tokens[4].value).to eq('"myheredoc"/')
945
+ expect(tokens[4].line).to eq(1)
946
+ expect(tokens[4].column).to eq(8)
947
+ expect(tokens[5].type).to eq(:NEWLINE)
948
+ expect(tokens[5].value).to eq("\n")
949
+ expect(tokens[5].line).to eq(1)
950
+ expect(tokens[5].column).to eq(23)
951
+ expect(tokens[6].type).to eq(:HEREDOC_PRE)
952
+ expect(tokens[6].value).to eq(" SOMETHING\n ")
953
+ expect(tokens[6].line).to eq(2)
954
+ expect(tokens[6].column).to eq(1)
955
+ expect(tokens[7].type).to eq(:VARIABLE)
956
+ expect(tokens[7].value).to eq("else")
957
+ expect(tokens[7].line).to eq(3)
958
+ expect(tokens[7].column).to eq(3)
959
+ expect(tokens[7].to_manifest).to eq("${else}")
960
+ expect(tokens[8].type).to eq(:HEREDOC_MID)
961
+ expect(tokens[8].value).to eq("\n AND :\n ")
962
+ expect(tokens[8].line).to eq(3)
963
+ expect(tokens[8].column).to eq(10)
964
+ expect(tokens[9].type).to eq(:UNENC_VARIABLE)
965
+ expect(tokens[9].value).to eq("another")
966
+ expect(tokens[9].line).to eq(5)
967
+ expect(tokens[9].column).to eq(3)
968
+ expect(tokens[9].to_manifest).to eq("$another")
969
+ expect(tokens[10].type).to eq(:HEREDOC_POST)
970
+ expect(tokens[10].value).to eq("\n THING\n ")
971
+ expect(tokens[10].raw).to eq("\n THING\n | myheredoc")
972
+ expect(tokens[10].line).to eq(5)
973
+ expect(tokens[10].column).to eq(11)
974
+ end
975
+
976
+ it 'should not remove the unnecessary $ from enclosed variables' do
977
+ manifest = <<-END.gsub(/^ {6}/, '')
978
+ $str = @("myheredoc"/)
979
+ ${$myvar}
980
+ |-myheredoc
981
+ END
982
+ tokens = @lexer.tokenise(manifest)
983
+
984
+ expect(tokens.length).to eq(10)
985
+
986
+ expect(tokens[7].type).to eq(:VARIABLE)
987
+ expect(tokens[7].value).to eq('myvar')
988
+ expect(tokens[7].raw).to eq('$myvar')
989
+ expect(tokens[7].to_manifest).to eq("${$myvar}")
990
+ end
991
+ end
992
+
633
993
  context ':CLASSREF' do
634
994
  it 'should match single capitalised alphanumeric term' do
635
995
  token = @lexer.tokenise('One').first
@@ -694,6 +1054,14 @@ describe PuppetLint::Lexer do
694
1054
  end
695
1055
  end
696
1056
 
1057
+ context ':FUNCTION_NAME' do
1058
+ it 'should match when a :NAME is followed by a :LPAREN' do
1059
+ token = @lexer.tokenise('my_function(').first
1060
+ expect(token.type).to eq(:FUNCTION_NAME)
1061
+ expect(token.value).to eq('my_function')
1062
+ end
1063
+ end
1064
+
697
1065
  context ':NUMBER' do
698
1066
  it 'should match numeric terms' do
699
1067
  token = @lexer.tokenise('1234567890').first
@@ -863,6 +1231,12 @@ describe PuppetLint::Lexer do
863
1231
  expect(tokens[2].type).to eq(:REGEX)
864
1232
  expect(tokens[14].type).to eq(:REGEX)
865
1233
  end
1234
+
1235
+ it 'should properly parse when a regex is provided as a function argument' do
1236
+ tokens = @lexer.tokenise('$somevar = $other_var.match(/([\w\.]+(:\d+)?(\/\w+)?)(:(\w+))?/)')
1237
+ expect(tokens[8].type).to eq(:REGEX)
1238
+ expect(tokens[8].value).to eq('([\w\.]+(:\d+)?(\/\w+)?)(:(\w+))?')
1239
+ end
866
1240
  end
867
1241
 
868
1242
  context ':STRING' do
@@ -877,5 +1251,32 @@ describe PuppetLint::Lexer do
877
1251
  expect(token.type).to eq(:STRING)
878
1252
  expect(token.value).to eq("\n")
879
1253
  end
1254
+
1255
+ it 'should handle interpolated values that contain double quotes' do
1256
+ manifest = %Q{"export bar=\\"${join(hiera('test'), "," )}\\""}
1257
+
1258
+ tokens = @lexer.tokenise(manifest)
1259
+ expect(tokens[0].type).to eq(:DQPRE)
1260
+ expect(tokens[0].value).to eq('export bar=\"')
1261
+ expect(tokens[1].type).to eq(:FUNCTION_NAME)
1262
+ expect(tokens[1].value).to eq('join')
1263
+ expect(tokens[2].type).to eq(:LPAREN)
1264
+ expect(tokens[3].type).to eq(:FUNCTION_NAME)
1265
+ expect(tokens[3].value).to eq('hiera')
1266
+ expect(tokens[4].type).to eq(:LPAREN)
1267
+ expect(tokens[5].type).to eq(:SSTRING)
1268
+ expect(tokens[5].value).to eq('test')
1269
+ expect(tokens[6].type).to eq(:RPAREN)
1270
+ expect(tokens[7].type).to eq(:COMMA)
1271
+ expect(tokens[8].type).to eq(:WHITESPACE)
1272
+ expect(tokens[8].value).to eq(' ')
1273
+ expect(tokens[9].type).to eq(:STRING)
1274
+ expect(tokens[9].value).to eq(',')
1275
+ expect(tokens[10].type).to eq(:WHITESPACE)
1276
+ expect(tokens[10].value).to eq(' ')
1277
+ expect(tokens[11].type).to eq(:RPAREN)
1278
+ expect(tokens[12].type).to eq(:DQPOST)
1279
+ expect(tokens[12].value).to eq('\"')
1280
+ end
880
1281
  end
881
1282
  end