blob: 61b5eb5a759b4cce144d182b107ac511528b29b7 (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.codegen;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.List;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author hmusum
*/
public class NormalizedDefinitionTest {
@Test
void testNormalizingFromReader() {
String def =
"aString string \n" +
"anInt int #comment \n" +
"aStringCommentCharacterAfter string default=\"ab\" #foo\n" +
"aStringWithCommentCharacter string default=\"a#b\"\n" +
"aStringWithEscapedQuote string default=\"a\"b\"\n";
StringReader reader = new StringReader(def);
NormalizedDefinition nd = new NormalizedDefinition();
List<String> out = null;
try {
nd.normalize(new BufferedReader(reader));
out = nd.getNormalizedContent();
} catch (IOException e) {
e.printStackTrace();
}
assertNotNull(out);
assertEquals(5, out.size());
assertEquals("aString string\n", out.get(0));
assertEquals("anInt int\n", out.get(1));
assertEquals("aStringCommentCharacterAfter string default=\"ab\"\n", out.get(2));
assertEquals("aStringWithCommentCharacter string default=\"a#b\"\n", out.get(3));
assertEquals("aStringWithEscapedQuote string default=\"a\"b\"\n", out.get(4));
reader.close();
}
@Test
void testNormalizingFromFile() throws IOException {
FileReader fileReader = null;
try {
fileReader = new FileReader("src/test/resources/configgen.allfeatures.def");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
NormalizedDefinition nd = new NormalizedDefinition();
List<String> out = null;
try {
nd.normalize(new BufferedReader(fileReader));
out = nd.getNormalizedContent();
} catch (IOException e) {
e.printStackTrace();
}
assertNotNull(out);
assertEquals(72, out.size());
assertNotNull(fileReader);
fileReader.close();
}
}
|