diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..8fa97f090 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,35 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + # Runs a single command using the runners shell + - name: Runs makefile on MarkdownParse + run: make test + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..8c0a899d9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} \ No newline at end of file diff --git a/MarkdownParse.java b/MarkdownParse.java index 5ebf83aba..1998c38ca 100644 --- a/MarkdownParse.java +++ b/MarkdownParse.java @@ -16,14 +16,22 @@ public static ArrayList getLinks(String markdown) { int closeBracket = markdown.indexOf("]", openBracket); int openParen = markdown.indexOf("(", closeBracket); int closeParen = markdown.indexOf(")", openParen); + + if (openBracket == -1 || closeBracket == -1 || + openParen == -1 || closeParen == -1) { + return toReturn; + } + + if (closeBracket + 1 != openParen) { + return toReturn; + } + toReturn.add(markdown.substring(openParen + 1, closeParen)); currentIndex = closeParen + 1; } - return toReturn; } - public static void main(String[] args) throws IOException { Path fileName = Path.of(args[0]); String content = Files.readString(fileName); diff --git a/MarkdownParseTest.java b/MarkdownParseTest.java new file mode 100644 index 000000000..ec6d7de88 --- /dev/null +++ b/MarkdownParseTest.java @@ -0,0 +1,67 @@ +import static org.junit.Assert.*; +import org.junit.*; + +import java.beans.Transient; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +// javac -cp ".;lib\junit-4.13.2.jar;lib\hamcrest-core-1.3.jar" *.java +// java -cp ".;lib/junit-4.13.2.jar;lib/hamcrest-core-1.3.jar" org.junit.runner.JUnitCore MarkdownParseTest + +public class MarkdownParseTest { + + @Test + public void addition() { + assertEquals(2, 1 + 1); + } + + @Test + public void subtraction() { + assertEquals(0, 1 - 1); + } + + @Test + public void getLinksTest1() throws IOException { + Path fileName = Path.of("test-file.md"); + String content = Files.readString(fileName); + List expectedLinks = List.of("https://something.com", "some-thing .html"); + assertEquals(expectedLinks, MarkdownParse.getLinks(content)); + } + + @Test + public void getLinksTest2() throws IOException { + Path fileName = Path.of("test-file2.md"); + String content = Files.readString(fileName); + List expectedLinks = List.of(); + assertEquals(expectedLinks, MarkdownParse.getLinks(content)); + } + + @Test + public void getLinksTest3() throws IOException { + Path fileName = Path.of("test-file3.md"); + String content = Files.readString(fileName); + List expectedLinks = List.of(); + assertEquals(expectedLinks, MarkdownParse.getLinks(content)); + } + + @Test + public void getLinksTest4() throws IOException { + Path fileName = Path.of("test-file4.md"); + String content = Files.readString(fileName); + List expectedLinks = List.of(); + assertEquals(expectedLinks, MarkdownParse.getLinks(content)); + } +} +======= + + @Test + public void getLinksMyTest() throws IOException { + Path fileName = Path.of("mytest.md"); + String content = Files.readString(fileName); + List expectedLinks = List.of(); + assertEquals(expectedLinks, MarkdownParse.getLinks(content)); + } +} +>>>>>>> 15651d09b55356d2bba16c937a420101cd9c202e diff --git a/config b/config new file mode 100644 index 000000000..825eb12c2 --- /dev/null +++ b/config @@ -0,0 +1,3 @@ +Host ieng6 + HostName ieng6.ucsd.edu + User cs15lsp22auv \ No newline at end of file diff --git a/lib/hamcrest-core-1.3.jar b/lib/hamcrest-core-1.3.jar new file mode 100644 index 000000000..9d5fe16e3 Binary files /dev/null and b/lib/hamcrest-core-1.3.jar differ diff --git a/lib/junit-4.13.2.jar b/lib/junit-4.13.2.jar new file mode 100644 index 000000000..6da55d8b8 Binary files /dev/null and b/lib/junit-4.13.2.jar differ diff --git a/makefile b/makefile new file mode 100644 index 000000000..687b893cf --- /dev/null +++ b/makefile @@ -0,0 +1,8 @@ +MarkdownParse.class: MarkdownParse.java + javac MarkdownParse.java + +MarkdownParseTest.class: MarkdownParseTest.java MarkdownParse.class + javac -cp .:lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar MarkdownParseTest.java + +test: MarkdownParseTest.class + java -cp .:lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar org.junit.runner.JUnitCore MarkdownParseTest diff --git a/mdparse b/mdparse new file mode 100644 index 000000000..242231aba --- /dev/null +++ b/mdparse @@ -0,0 +1 @@ +java -cp lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar:.MarkdownParse $1 diff --git a/snippet1 b/snippet1 new file mode 100644 index 000000000..1019d16bb --- /dev/null +++ b/snippet1 @@ -0,0 +1,7 @@ +`[a link`](url.com) + +[another link](`google.com)` + +[`cod[e`](google.com) + +[`code]`](ucsd.edu) \ No newline at end of file diff --git a/snippet2 b/snippet2 new file mode 100644 index 000000000..3fb8eb27e --- /dev/null +++ b/snippet2 @@ -0,0 +1,5 @@ +[a [nested link](a.com)](b.com) + +[a nested parenthesized url](a.com(())) + +[some escaped \[ brackets \]](example.com) \ No newline at end of file diff --git a/snippet3 b/snippet3 new file mode 100644 index 000000000..940b2cab9 --- /dev/null +++ b/snippet3 @@ -0,0 +1,24 @@ +[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 \ No newline at end of file diff --git a/test-file.md b/test-file.md index 0f9fbc913..40760ea0d 100644 --- a/test-file.md +++ b/test-file.md @@ -1,4 +1,4 @@ # Title [link1](https://something.com) -[link2](some-thing.html) +[link2](some-thing.html) \ No newline at end of file diff --git a/test-file2.md b/test-file2.md new file mode 100644 index 000000000..0387d362e --- /dev/null +++ b/test-file2.md @@ -0,0 +1,3 @@ +#title + +[link]( \ No newline at end of file diff --git a/test-file3.md b/test-file3.md new file mode 100644 index 000000000..242dbec09 --- /dev/null +++ b/test-file3.md @@ -0,0 +1,3 @@ +# title + +[link( \ No newline at end of file diff --git a/test-file4.md b/test-file4.md new file mode 100644 index 000000000..03d95aa8f --- /dev/null +++ b/test-file4.md @@ -0,0 +1,7 @@ +# title + +[stuff] + +paragraph + +(page.com) \ No newline at end of file