-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarkdownParseTest.java
More file actions
129 lines (102 loc) · 4.42 KB
/
MarkdownParseTest.java
File metadata and controls
129 lines (102 loc) · 4.42 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import static org.junit.Assert.*;
import org.junit.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.*;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
public class MarkdownParseTest {
/**
@Test
public void addition() {
assertEquals(2, 1+1);
}
public String readFile(String file) throws IOException {
Path fileName = Path.of(file);
String contents = Files.readString(fileName);
return contents;
}
@Test
public void testBaseCase() throws IOException {
String contents = readFile("test-file.md");
ArrayList<String> links = MarkdownParse.getLinks(contents);
ArrayList<String> Reallinks =
new ArrayList<>(List.of("https://something.com", "some-page.html"));
assertArrayEquals(links.toArray(), Reallinks.toArray());
}
@Test
public void testEmptyCase() throws IOException {
String contents = readFile("test-empty.md");
ArrayList<String> links = MarkdownParse.getLinks(contents);
ArrayList<String> Reallinks = new ArrayList<>(List.of());
assertArrayEquals(links.toArray(), Reallinks.toArray());
}
@Test
public void testNewLine() throws IOException {
String contents = readFile("test-file-newline.md");
ArrayList<String> links = MarkdownParse.getLinks(contents);
ArrayList<String> Reallinks =
new ArrayList<>(List.of("https://something.com", "some-page.html"));
assertArrayEquals(links.toArray(), Reallinks.toArray());
}
@Test
public void testBackSlash() throws IOException {
String contents = readFile("test-backslash-escapes.md");
ArrayList<String> links = MarkdownParse.getLinks(contents);
ArrayList<String> Reallinks = new ArrayList<>(List.of("/close_bracket", "/single_)bracket",
"/double_\\", "/triple_\\)bracket", "/quad_\\\\", "/open_(paren"));
assertArrayEquals(links.toArray(), Reallinks.toArray());
}
@Test
public void testEndingText() throws IOException {
String contents = readFile("test-ending-text.md");
ArrayList<String> links = MarkdownParse.getLinks(contents);
ArrayList<String> Reallinks =
new ArrayList<>(List.of("https://something.com", "some-page.html"));
assertArrayEquals(links.toArray(), Reallinks.toArray());
}
@Test
public void testIgnoreImage() throws IOException {
String contents = readFile("test-ignore-image.md");
ArrayList<String> links = MarkdownParse.getLinks(contents);
ArrayList<String> Reallinks =
new ArrayList<>(List.of("/actual_link1", "/actual_link2", "/actual_link3"));
assertArrayEquals(links.toArray(), Reallinks.toArray());
}
@Test
public void testBackSlash2() throws IOException {
String contents = readFile("test-backslash-escapes2.md");
ArrayList<String> links = MarkdownParse.getLinks(contents);
ArrayList<String> Reallinks = new ArrayList<>(List.of("/close_bracket", "/single_)bracket",
"/double_\\", "/triple_\\)bracket", "/quad_\\\\", "/open_(paren"));
assertArrayEquals(links.toArray(), Reallinks.toArray());
}
@Test
public void testSnippets() throws IOException
{
Path fileName = Path.of("snippet-1.md");
String contents = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(contents);
ArrayList<String> Reallinks = new ArrayList<>(List.of("google.com", "google.com", "ucsd.edu"));
assertArrayEquals(Reallinks.toArray(),links.toArray());
}
@Test
public void testSnippets2() throws IOException
{
Path fileName = Path.of("snippet-2.md");
String contents = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(contents);
ArrayList<String> Reallinks = new ArrayList<>(List.of("a.com", "a.com", "example.com"));
assertArrayEquals(Reallinks.toArray(),links.toArray());
}*/
@Test
public void testSnippets3() throws IOException
{
Path fileName = Path.of("snippet-3.md");
String contents = Files.readString(fileName);
ArrayList<String> links = MarkdownParse.getLinks(contents);
ArrayList<String> Reallinks = new ArrayList<>(List.of("https://ucsd-cse15l-w22.github.io/"));
assertArrayEquals(Reallinks.toArray(),links.toArray());
}
}