Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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@v2

# 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: |
make test
43 changes: 37 additions & 6 deletions MarkdownParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,44 @@ public static ArrayList<String> getLinks(String markdown) {
// find the next [, then find the ], then find the (, then take up to
// the next )
int currentIndex = 0;
while(currentIndex < markdown.length()) {
while(markdown.indexOf("[", currentIndex) != -1) {
int nextOpenBracket = markdown.indexOf("[", currentIndex);
int nextCloseBracket = markdown.indexOf("]", nextOpenBracket);
int openParen = markdown.indexOf("(", nextCloseBracket);
int closeParen = markdown.indexOf(")", openParen);
toReturn.add(markdown.substring(openParen + 1, closeParen));
currentIndex = closeParen + 1;
if(nextOpenBracket != 0 && markdown.charAt(nextOpenBracket - 1) == '!'){
int nextCloseBracket = markdown.indexOf("]", nextOpenBracket);
if(nextCloseBracket == -1){
nextCloseBracket = nextOpenBracket;
}
int openParen = markdown.indexOf("(", nextCloseBracket);
if(openParen == -1){
openParen = nextOpenBracket;
}
int closeParen = markdown.indexOf(")", openParen);
if(closeParen == -1){
closeParen = openParen;
}
currentIndex = closeParen + 1;
}
else{
int nextCloseBracket = markdown.indexOf("]", nextOpenBracket);
if(nextCloseBracket == -1){
nextCloseBracket = nextOpenBracket;
}
int openParen = markdown.indexOf("(", nextCloseBracket);
if(openParen == -1){
openParen = nextOpenBracket;
}
int closeParen = markdown.indexOf(")", openParen);
if(closeParen == -1){
closeParen = openParen;
}
if(nextCloseBracket != openParen - 1){
currentIndex = closeParen + 1;
}
else{
toReturn.add(markdown.substring(openParen + 1, closeParen));
currentIndex = closeParen + 1;
}
}
}
return toReturn;
}
Expand Down
51 changes: 51 additions & 0 deletions MarkdownParseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
import static org.junit.Assert.*;
import org.junit.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

public class MarkdownParseTest{
String file1;
String file2;
String file3;
@Before
public void setUp() throws IOException{
file1 = Files.readString(Path.of("test-file.md"));
file2 = Files.readString(Path.of("test-file2.md"));
file3 = Files.readString(Path.of("test-file3.md"));
}
@Test
public void addition(){
assertEquals(2, 1+1);
}
@Test
public void testGetLinks(){
assertEquals(List.of("https://something.com", "some-page.html"), MarkdownParse.getLinks(file1));
assertEquals(List.of("https://something.com", "some-page.html"), MarkdownParse.getLinks(file2));
assertEquals(List.of(), MarkdownParse.getLinks(file3));

}
}
*/

import static org.junit.Assert.*;
import org.junit.*;

import java.io.IOException;
import java.nio.file.*;
import java.util.*;
public class MarkdownParseTest {

@Test
public void improvmentTest() throws IOException{
Path fileName = Path.of("test-file-l5.md");
String contents = Files.readString(fileName);

assertEquals(List.of("something.com()"), MarkdownParse.getLinks(contents));
}


}
2 changes: 2 additions & 0 deletions bug-maker-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

[a link]!](www.link.com/dsajlfldkjsajklf)
3 changes: 3 additions & 0 deletions bug-maker-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


[a link](www.link.com/)dsajlfldkjsajklf)
2 changes: 2 additions & 0 deletions bug-maker-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

[a link
Binary file added lib/hamcrest-core-1.3.jar
Binary file not shown.
Binary file added lib/junit-4.13.2.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

test : MarkdownParse.java
javac -cp .:lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar MarkdownParseTest.java
java -cp .:lib/junit-4.13.2.jar:lib/hamcrest-core-1.3.jar org.junit.runner.JUnitCore MarkdownParseTest
1 change: 1 addition & 0 deletions test-file-l5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[link](something.com()))
6 changes: 6 additions & 0 deletions test-file2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Title

[a link!](https://something.com)
[another link!](some-page.html)

some paragraph text after the links
5 changes: 5 additions & 0 deletions test-file3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# title

[]

more text here
3 changes: 3 additions & 0 deletions test-file4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# title

[]link goes here!
7 changes: 7 additions & 0 deletions test-file5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# title

[stuff]

paragraph

(page.com)
3 changes: 3 additions & 0 deletions test-file6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# title

![link](page.com)
1 change: 1 addition & 0 deletions test-file7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
)[
2 changes: 2 additions & 0 deletions test-file8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[](a link on the first line)
[