@@ -52,26 +52,67 @@ public function getNonStringMappingKeysData()
52
52
return $ this ->loadTestsFromFixtureFiles ('nonStringKeys.yml ' );
53
53
}
54
54
55
- public function testTabsInYaml ()
55
+ /**
56
+ * @dataProvider invalidIndentation
57
+ */
58
+ public function testTabsAsIndentationInYaml (string $ given , string $ expectedMessage )
56
59
{
57
- // test tabs in YAML
58
- $ yamls = [
59
- "foo: \n bar " ,
60
- "foo: \n bar " ,
61
- "foo: \n bar " ,
62
- "foo: \n bar " ,
60
+ $ this ->expectException (ParseException::class);
61
+ $ this ->expectExceptionMessage ($ expectedMessage );
62
+ $ this ->parser ->parse ($ given );
63
+ }
64
+
65
+ public function invalidIndentation (): array
66
+ {
67
+ return [
68
+ [
69
+ "foo: \n\tbar " ,
70
+ "A YAML file cannot contain tabs as indentation at line 2 (near \"\tbar \"). " ,
71
+ ],
72
+ [
73
+ "foo: \n \tbar " ,
74
+ "A YAML file cannot contain tabs as indentation at line 2 (near \"\tbar \"). " ,
75
+ ],
76
+ [
77
+ "foo: \n\t bar " ,
78
+ "A YAML file cannot contain tabs as indentation at line 2 (near \"\t bar \"). " ,
79
+ ],
80
+ [
81
+ "foo: \n \t bar " ,
82
+ "A YAML file cannot contain tabs as indentation at line 2 (near \"\t bar \"). " ,
83
+ ],
63
84
];
85
+ }
64
86
65
- foreach ($ yamls as $ yaml ) {
66
- try {
67
- $ this ->parser ->parse ($ yaml );
87
+ /**
88
+ * @dataProvider validTokenSeparators
89
+ */
90
+ public function testValidTokenSeparation (string $ given , array $ expected )
91
+ {
92
+ $ actual = $ this ->parser ->parse ($ given );
93
+ $ this ->assertEquals ($ expected , $ actual );
94
+ }
68
95
69
- $ this ->fail ('YAML files must not contain tabs ' );
70
- } catch (\Exception $ e ) {
71
- $ this ->assertInstanceOf (\Exception::class, $ e , 'YAML files must not contain tabs ' );
72
- $ this ->assertEquals ('A YAML file cannot contain tabs as indentation at line 2 (near " ' .strpbrk ($ yaml , "\t" ).'"). ' , $ e ->getMessage (), 'YAML files must not contain tabs ' );
73
- }
74
- }
96
+ public function validTokenSeparators (): array
97
+ {
98
+ return [
99
+ [
100
+ 'foo: bar ' ,
101
+ ['foo ' => 'bar ' ],
102
+ ],
103
+ [
104
+ "foo: \tbar " ,
105
+ ['foo ' => 'bar ' ],
106
+ ],
107
+ [
108
+ "foo: \tbar " ,
109
+ ['foo ' => 'bar ' ],
110
+ ],
111
+ [
112
+ "foo: \t bar " ,
113
+ ['foo ' => 'bar ' ],
114
+ ],
115
+ ];
75
116
}
76
117
77
118
public function testEndOfTheDocumentMarker ()
0 commit comments