31
31
public class SourceCodeProviderTest {
32
32
33
33
private final SourceCodeProvider codeProvider = new SourceCodeProvider ();
34
- private final File expected = new File (new File ("src/test/resources/codeprovider/source.hh" ).getAbsolutePath ());
35
-
34
+ private final File expected1 = new File (new File ("src/test/resources/codeprovider/source.hh" ).getAbsolutePath ());
35
+ private final File expected2 = new File (new File ("src/test/resources/codeprovider/source" ).getAbsolutePath ());
36
+
36
37
// ////////////////////////////////////////////////////////////////////////////
37
38
// Behavior in the absolute path case
38
39
@ Test
@@ -41,13 +42,13 @@ public void getting_file_with_abspath() {
41
42
// working directory and should work the same in the quoted and
42
43
// unquoted case
43
44
44
- String path = expected .getAbsolutePath ();
45
+ String path = expected1 .getAbsolutePath ();
45
46
String dummycwd = new File ("src/test/resources/codeprovider" ).getAbsolutePath ();
46
47
47
- assertEquals (expected , codeProvider .getSourceCodeFile (path , null , true ));
48
- assertEquals (expected , codeProvider .getSourceCodeFile (path , null , false ));
49
- assertEquals (expected , codeProvider .getSourceCodeFile (path , dummycwd , true ));
50
- assertEquals (expected , codeProvider .getSourceCodeFile (path , dummycwd , false ));
48
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , null , true ));
49
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , null , false ));
50
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , dummycwd , true ));
51
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , dummycwd , false ));
51
52
}
52
53
53
54
// ////////////////////////////////////////////////////////////////////////////
@@ -66,10 +67,22 @@ public void getting_file_relpath_case1() {
66
67
String includeRoot = new File ("src/test/resources/codeprovider" ).getAbsolutePath ();
67
68
68
69
codeProvider .setIncludeRoots (Arrays .asList (includeRoot ), baseDir );
69
- assertEquals (expected , codeProvider .getSourceCodeFile (path , dummycwd , true ));
70
- assertEquals (expected , codeProvider .getSourceCodeFile (path , dummycwd , false ));
70
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , dummycwd , true ));
71
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , dummycwd , false ));
71
72
}
72
73
74
+ @ Test
75
+ public void getting_file_relpath_case1_without_extension () {
76
+ String baseDir = new File ("src/test" ).getAbsolutePath ();
77
+ String dummycwd = "/" ;
78
+ String path = "source" ;
79
+ String includeRoot = new File ("src/test/resources/codeprovider" ).getAbsolutePath ();
80
+
81
+ codeProvider .setIncludeRoots (Arrays .asList (includeRoot ), baseDir );
82
+ assertEquals (expected2 , codeProvider .getSourceCodeFile (path , dummycwd , true ));
83
+ assertEquals (expected2 , codeProvider .getSourceCodeFile (path , dummycwd , false ));
84
+ }
85
+
73
86
@ Test
74
87
public void getting_file_relpath_case2 () {
75
88
String baseDir = new File ("src/test" ).getAbsolutePath ();
@@ -78,10 +91,22 @@ public void getting_file_relpath_case2() {
78
91
String includeRoot = "resources/codeprovider" ;
79
92
80
93
codeProvider .setIncludeRoots (Arrays .asList (includeRoot ), baseDir );
81
- assertEquals (expected , codeProvider .getSourceCodeFile (path , dummycwd , true ));
82
- assertEquals (expected , codeProvider .getSourceCodeFile (path , dummycwd , false ));
94
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , dummycwd , true ));
95
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , dummycwd , false ));
83
96
}
84
97
98
+ @ Test
99
+ public void getting_file_relpath_case2_without_extension () {
100
+ String baseDir = new File ("src/test" ).getAbsolutePath ();
101
+ String dummycwd = "/" ;
102
+ String path = "source" ;
103
+ String includeRoot = "resources/codeprovider" ;
104
+
105
+ codeProvider .setIncludeRoots (Arrays .asList (includeRoot ), baseDir );
106
+ assertEquals (expected2 , codeProvider .getSourceCodeFile (path , dummycwd , true ));
107
+ assertEquals (expected2 , codeProvider .getSourceCodeFile (path , dummycwd , false ));
108
+ }
109
+
85
110
@ Test
86
111
public void getting_file_relpath_case3 () {
87
112
String baseDir = new File ("src/test" ).getAbsolutePath ();
@@ -90,10 +115,22 @@ public void getting_file_relpath_case3() {
90
115
String includeRoot = new File ("src/test/resources" ).getAbsolutePath ();
91
116
92
117
codeProvider .setIncludeRoots (Arrays .asList (includeRoot ), baseDir );
93
- assertEquals (expected , codeProvider .getSourceCodeFile (path , dummycwd , true ));
94
- assertEquals (expected , codeProvider .getSourceCodeFile (path , dummycwd , false ));
118
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , dummycwd , true ));
119
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , dummycwd , false ));
95
120
}
96
121
122
+ @ Test
123
+ public void getting_file_relpath_case3_without_extension () {
124
+ String baseDir = new File ("src/test" ).getAbsolutePath ();
125
+ String dummycwd = "/" ;
126
+ String path = "codeprovider/source" ;
127
+ String includeRoot = new File ("src/test/resources" ).getAbsolutePath ();
128
+
129
+ codeProvider .setIncludeRoots (Arrays .asList (includeRoot ), baseDir );
130
+ assertEquals (expected2 , codeProvider .getSourceCodeFile (path , dummycwd , true ));
131
+ assertEquals (expected2 , codeProvider .getSourceCodeFile (path , dummycwd , false ));
132
+ }
133
+
97
134
@ Test
98
135
public void getting_file_relpath_case4 () {
99
136
String baseDir = new File ("src/test" ).getAbsolutePath ();
@@ -102,39 +139,56 @@ public void getting_file_relpath_case4() {
102
139
String includeRoot = "resources" ;
103
140
104
141
codeProvider .setIncludeRoots (Arrays .asList (includeRoot ), baseDir );
105
- assertEquals (expected , codeProvider .getSourceCodeFile (path , dummycwd , true ));
106
- assertEquals (expected , codeProvider .getSourceCodeFile (path , dummycwd , false ));
142
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , dummycwd , true ));
143
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , dummycwd , false ));
107
144
}
108
145
146
+ @ Test
147
+ public void getting_file_relpath_case4_without_extension () {
148
+ String baseDir = new File ("src/test" ).getAbsolutePath ();
149
+ String dummycwd = "/" ;
150
+ String path = "codeprovider/source" ;
151
+ String includeRoot = "resources" ;
152
+
153
+ codeProvider .setIncludeRoots (Arrays .asList (includeRoot ), baseDir );
154
+ assertEquals (expected2 , codeProvider .getSourceCodeFile (path , dummycwd , true ));
155
+ assertEquals (expected2 , codeProvider .getSourceCodeFile (path , dummycwd , false ));
156
+ }
157
+
109
158
// ////////////////////////////////////////////////////////////////////////////
110
159
// Special behavior in the quoted case
111
160
// Lookup in the current directory. Has to fail for the angle case
112
161
@ Test
113
162
public void getting_file_with_filename_and_cwd () {
114
163
String cwd = new File ("src/test/resources/codeprovider" ).getAbsolutePath ();
115
164
String path = "source.hh" ;
116
- assertEquals (expected , codeProvider .getSourceCodeFile (path , cwd , true ));
165
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , cwd , true ));
117
166
assertEquals (null , codeProvider .getSourceCodeFile (path , cwd , false ));
118
167
}
119
168
120
169
@ Test
121
170
public void getting_file_with_relpath_and_cwd () {
122
171
String cwd = new File ("src/test/resources" ).getAbsolutePath ();
123
172
String path = "codeprovider/source.hh" ;
124
- assertEquals (expected , codeProvider .getSourceCodeFile (path , cwd , true ));
173
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , cwd , true ));
125
174
assertEquals (null , codeProvider .getSourceCodeFile (path , cwd , false ));
126
175
}
127
176
128
177
@ Test
129
178
public void getting_file_with_relpath_containing_backsteps_and_cwd () {
130
179
String cwd = new File ("src/test/resources/codeprovider/folder" ).getAbsolutePath ();
131
180
String path = "../source.hh" ;
132
- assertEquals (expected , codeProvider .getSourceCodeFile (path , cwd , true ));
181
+ assertEquals (expected1 , codeProvider .getSourceCodeFile (path , cwd , true ));
133
182
assertEquals (null , codeProvider .getSourceCodeFile (path , cwd , false ));
134
183
}
135
184
136
185
@ Test
137
- public void getting_source_code () throws IOException {
138
- assertEquals ("source code" , codeProvider .getSourceCode (expected , Charset .defaultCharset ()));
186
+ public void getting_source_code1 () throws IOException {
187
+ assertEquals ("source code" , codeProvider .getSourceCode (expected1 , Charset .defaultCharset ()));
188
+ }
189
+
190
+ @ Test
191
+ public void getting_source_code2 () throws IOException {
192
+ assertEquals ("source code" , codeProvider .getSourceCode (expected2 , Charset .defaultCharset ()));
139
193
}
140
194
}
0 commit comments