diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..0ec09dd --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,36 @@ +# 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: Run a one-line script + run: echo Hello, world! + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + javac -cp .:lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar MarkdownParseTest.java MarkdownParse.java + java -cp .:lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar org.junit.runner.JUnitCore MarkdownParseTest diff --git a/MarkdownParse.class b/MarkdownParse.class new file mode 100644 index 0000000..ca7840e Binary files /dev/null and b/MarkdownParse.class differ diff --git a/MarkdownParse.java b/MarkdownParse.java index 5ebf83a..1bf7432 100644 --- a/MarkdownParse.java +++ b/MarkdownParse.java @@ -11,23 +11,39 @@ public static ArrayList getLinks(String markdown) { ArrayList toReturn = new ArrayList<>(); // find the next [, then find the ], then find the (, then read link upto next ) int currentIndex = 0; - while(currentIndex < markdown.length()) { - int openBracket = markdown.indexOf("[", currentIndex); + while(currentIndex < markdown.length()||openBracket!=null||closeBracket!=null||openParen!=null||closeParen!=null) { + int openBracket = MarkdownParse.checkOpenBracket(markdown, currentIndex); int closeBracket = markdown.indexOf("]", openBracket); int openParen = markdown.indexOf("(", closeBracket); + if(openBracket == -1 || closeBracket == -1){ + break; + } int closeParen = markdown.indexOf(")", openParen); + if(openBracket == -1){ + break; + } toReturn.add(markdown.substring(openParen + 1, closeParen)); + currentIndex = closeParen + 1; + } return toReturn; } + public static int checkOpenBracket(String markdown, int currentIndex){ + int openBracket = markdown.indexOf("[", currentIndex); + if(openBracket == -1){ + return null; + } + return openBracket; + } public static void main(String[] args) throws IOException { Path fileName = Path.of(args[0]); - String content = Files.readString(fileName); - ArrayList links = getLinks(content); + String contentOfFile = Files.readString(fileName); + ArrayList links = getLinks(contentOfFile); System.out.println(links); + } } diff --git a/MarkdownParseTest.class b/MarkdownParseTest.class new file mode 100644 index 0000000..7c66198 Binary files /dev/null and b/MarkdownParseTest.class differ diff --git a/MarkdownParseTest.java b/MarkdownParseTest.java index 376d592..896bfc9 100644 --- a/MarkdownParseTest.java +++ b/MarkdownParseTest.java @@ -1,10 +1,72 @@ import static org.junit.Assert.*; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + import org.junit.*; public class MarkdownParseTest { @Test - public void addition() { + public void addition(){ assertEquals(2, 1 + 1); + + } + + + @Test + public void testLinks1() throws IOException{ + String content = Files.readString(Path.of("test-file.md")); + assertEquals(List.of("https://something.com", "some-thing.html"), MarkdownParse.getLinks(content)); } + @Test + public void testLinks2() throws IOException{ + String content = Files.readString(Path.of("test-file2.md")); + assertEquals(List.of("https://google.com", "some-thing.html"), MarkdownParse.getLinks(content)); + } + + @Test + public void testLinks3() throws IOException{ + String content = Files.readString(Path.of("test-file3.md")); + assertEquals(List.of("more text here"), MarkdownParse.getLinks(content)); + } + + @Test + public void testLinks7() throws IOException{ + String content = Files.readString(Path.of("test-file7.md")); + assertEquals(true, MarkdownParse.getLinks(content).isEmpty()); + } + + //New Test + @Test + public void getCorrectLinks4() throws IOException{ + String content = Files.readString(Path.of("test-file4.md")); + assertEquals(List.of(""),MarkdownParse.getLinks(content)); + } + + //New Test + @Test + public void getCorrectLinks5() throws IOException{ + String content = Files.readString(Path.of("test-file5.md")); + assertEquals(List.of("page.com"),MarkdownParse.getLinks(content)); + } + + //New Test + @Test + public void getCorrectLinks6() throws IOException{ + String content = Files.readString(Path.of("test-file6.md")); + assertEquals(List.of(""),MarkdownParse.getLinks(content)); + } + + //New Test + @Test + public void getCorrectLinks8() throws IOException{ + String content = Files.readString(Path.of("test-file8.md")); + assertEquals(List.of("a link on the first line"),MarkdownParse.getLinks(content)); + } + + + } \ No newline at end of file diff --git a/cd b/cd new file mode 100644 index 0000000..fde4666 --- /dev/null +++ b/cd @@ -0,0 +1,3 @@ +Host ieng6 + HostName ieng6.ucsd.edu + User cs15ls122au diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000..e69de29