Link to my markdown-parser
repo
Link to the repo that I reviewed
Snippet 1
`[a link`](url.com)
[another link](`google.com)`
[`cod[e`](google.com)
[`code]`](ucsd.edu)
JUnit Tests
I renamed the group’s file name for MarkdownParse
to toReview
.
@Test
public void testSnippet1() throws IOException {
Path fileName = Path.of("snippet1.md");
String content = Files.readString(fileName);
ArrayList<String> exp = new ArrayList<>();
assertEquals(exp, MarkdownParse.getLinks(content));
assertEquals(exp, toReview.getLinks(content));
}
I used VScode’s MD preview tool to decide what links to put in exp
.
Preview of Snippet in MD:
[a link
](url.com)
Running My Implementation
1) testSnippet1(MarkdownParseTest)
java.lang.AssertionError: expected:<[`google.com, google.com, ucsd.edu]> but was:<[url.com, `google.com, google.com, ucsd.edu]>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:120)
at org.junit.Assert.assertEquals(Assert.java:146)
at MarkdownParseTest.testSnippet1(MarkdownParseTest.java:147)
Running Their Implementation
1) testSnippet1(MarkdownParseTest)
java.lang.AssertionError: expected:<[`google.com, google.com, ucsd.edu]> but was:<[url.com, `google.com, google.com, ucsd.edu]>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:120)
at org.junit.Assert.assertEquals(Assert.java:146)
at MarkdownParseTest.testSnippet1(MarkdownParseTest.java:147)
Changes
A short code change I could implement is make the getLinks()
method ignore brackets that are within a set of 2 backticks. This way, it would not count [a link
](url.com) as a link because it would be missing the first bracket, as it is between two backticks.
Snippet 2
[a [nested link](a.com)](b.com)
[a nested parenthesized url](a.com(()))
[some escaped \[ brackets \]](example.com)
JUnit Tests
I renamed the group’s file name for MarkdownParse
to toReview
.
@Test
public void testSnippet2() throws IOException {
Path fileName = Path.of("snippet2.md");
String content = Files.readString(fileName);
ArrayList<String> exp = new ArrayList<>();
assertEquals(exp, MarkdownParse.getLinks(content));
assertEquals(exp, toReview.getLinks(content));
}
I used VScode’s MD preview tool to decide what links to put in exp
.
Preview of Snippet in MD:
Running My Implementation
1) testSnippet2(MarkdownParseTest)
java.lang.AssertionError: expected:<[a.com, a.com(()), example.com]> but was:<[a.com, a.com((, example.com]>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:120)
at org.junit.Assert.assertEquals(Assert.java:146)
at MarkdownParseTest.testSnippet2(MarkdownParseTest.java:159)
Running Their Implementation
1) testSnippet2(MarkdownParseTest)
java.lang.AssertionError: expected:<[a.com, a.com(()), example.com]> but was:<[a.com, a.com((, example.com]>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:120)
at org.junit.Assert.assertEquals(Assert.java:146)
at MarkdownParseTest.testSnippet2(MarkdownParseTest.java:160)
Changes
I think a more involved code change would be needed to fix the issue of nested parentheses. For example, the program would need to recognize which closing parentheses is the true closing parentheses, rather than it just being part of the link and this could get tricky when there are multiple opening and closing parentheses nested. For this, I can use a stack data structure to keep track of the nested parentheses.
Snippet 3
[this title text is really long and takes up more than
one line
and has some line breaks](
https://www.twitter.com
)
[this title text is really long and takes up more than
one line](
https://sites.google.com/eng.ucsd.edu/cse-15l-spring-2022/schedule
)
[this link doesn't have a closing parenthesis](github.com
And there's still some more text after that.
[this link doesn't have a closing parenthesis for a while](https://cse.ucsd.edu/
)
And then there's more text
JUnit Tests
I renamed the group’s file name for MarkdownParse
to toReview
.
@Test
public void testSnippet3() throws IOException {
Path fileName = Path.of("snippet3.md");
String content = Files.readString(fileName);
ArrayList<String> exp = new ArrayList<>();
assertEquals(exp, MarkdownParse.getLinks(content));
assertEquals(exp, toReview.getLinks(content));
}
I used VScode’s MD preview tool to decide what links to put in exp
.
Preview of Snippet in MD:
[this title text is really long and takes up more than one line
and has some line breaks]( https://www.twitter.com )
this title text is really long and takes up more than one line
[this link doesn’t have a closing parenthesis](github.com
And there’s still some more text after that.
[this link doesn’t have a closing parenthesis for a while](https://cse.ucsd.edu/
)
And then there’s more text
Running My Implementation
1) testSnippet3(MarkdownParseTest)
java.lang.AssertionError: expected:<[https://www.twitter.com, https://sites.google.com/eng.ucsd.edu/cse-15l-spring-2022/schedule, https://cse.ucsd.edu/]> but was:<[
https://sites.google.com/eng.ucsd.edu/cse-15l-spring-2022/schedule
]>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:120)
at org.junit.Assert.assertEquals(Assert.java:146)
at MarkdownParseTest.testSnippet3(MarkdownParseTest.java:172)
Running Their Implementation
1) testSnippet3(MarkdownParseTest)
java.lang.AssertionError: expected:<[https://www.twitter.com, https://sites.google.com/eng.ucsd.edu/cse-15l-spring-2022/schedule, https://cse.ucsd.edu/]> but was:<[
https://www.twitter.com
,
https://sites.google.com/eng.ucsd.edu/cse-15l-spring-2022/schedule
, github.com
And there's still some more text after that.
[this link doesn't have a closing parenthesis for a while](https://cse.ucsd.edu/
]>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:120)
at org.junit.Assert.assertEquals(Assert.java:146)
at MarkdownParseTest.testSnippet3(MarkdownParseTest.java:173)
Changes
I think a more involved code change would be needed to fix the issue of nested parentheses. For example, the program would need to recognize which closing parentheses is the true closing parentheses, rather than it just being part of the link and this could get tricky when there are multiple opening and closing parentheses nested. For this, I can use a stack data structure to keep track of the nested parentheses.