Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yacubane committed Jun 24, 2019
2 parents d780656 + b2f1c80 commit 218dedc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,16 @@ Inside application you can use various commands:
</a>
</h1>

- Solving quadratic equation
- Script to delete all files with selected extensions in Python
<h1 align="center">
<a href="https://asciinema.org/a/253160">
<img src="https://asciinema.org/a/253160.png" width="50%">
</a>
</h1>

- Solving Quadratic equation in Python
<h1 align="center">
<a href="https://asciinema.org/a/E8MvrBlh15Rubv1wFO4KcDoKr">
<img src="https://asciinema.org/a/E8MvrBlh15Rubv1wFO4KcDoKr.png" width="50%">
</a>
</h1>
50 changes: 42 additions & 8 deletions src/main/tests/ParserTest.scala
Original file line number Diff line number Diff line change
@@ -1,28 +1,62 @@
import org.scalatest.FunSuite
import overlang.stackOverflowBackend.{StackOverflowAnswer, StackOverflowConnection, StackOverflowQuestion, StackOverflowWrongIdException}
import overlang.stackOverflowBackend.StackOverflowParser._
import overlang.terminal.SearchResult

class ParserTest extends FunSuite {
test("test parse simple to list of code") {
test("parse answer body to list of code") {
val myBody = "<pre><code>test</code></pre>"
assert(parseAnswerBody(myBody) == List("test"))
parseAnswerBody(myBody) === List("test")
}

test("test parse with tag class to list of code") {
test("parse answer body with tag class to list of code") {
val myBody = "<pre class = 'sth'><code>test</code></pre>"
assert(parseAnswerBody(myBody) == List("test"))
parseAnswerBody(myBody) === List("test")
}

test("test parse with HTML lt and gt to list of code") {
test("parse answer body with HTML lt and gt to list of code") {
val myBody = "<pre class = 'sth'><code>&lt;&lt;test&gt;&gt;</code></pre>"
assert(parseAnswerBody(myBody) == List("<<test>>"))
parseAnswerBody(myBody) === List("<<test>>")
}

test("test parse many codes") {
test("parse answer body with many codes") {
val myBody = "not importat something " +
"<pre class = 'whatever' ><code>&lt;&lt;test1&gt;&gt;</code></pre>" +
"<pre class = 'sth'><code>&lt;&lt;test2&gt;&gt;</code></pre>" +
"<pre class = 'sth'><code>&lt;&lt;test3&gt;&gt;</code></pre>" +
"blah blah blah"
assert(parseAnswerBody(myBody) == List("<<test1>>", "<<test2>>", "<<test3>>"))
parseAnswerBody(myBody) === List("<<test1>>", "<<test2>>", "<<test3>>")
}


test("parse whole answer, should throw error, with no answer") {
val myAns = "{\"items\": [] }"
assertThrows[StackOverflowWrongIdException](parseAnswer(myAns))
}

test("parse whole correct StackOverflowAnswer") {

val myRequest = "{\"items\": [{\"tags\":[\"tag1\"], \"score\": 33, " +
"\"answer_id\": 1234, \"body\": \"<pre><code>yo</pre></code>\"}]}"


val myAnswer = parseAnswer(myRequest)
myAnswer === new StackOverflowAnswer(1234, 33, List("yo"), List("tag1"))
}


test("parse whole correct SearchResult") {

val myRequest = "{\"items\": [{\"item_type\": \"question\", \"question_id\": 1234, " +
"\"question_score\": 4321, \"title\": \"best question\"}, " +
"{\"item_type\": \"answer\",\"tags\":[\"tags1\"], \"score\": 545, \"answer_id\": 2334, \"body\": \"<pre><code>code1</pre></code>\"}]}"


val mySearchRes = parseSearchResult(myRequest)

mySearchRes === List[SearchResult](
new StackOverflowQuestion(1234, "best question", 4321),
new StackOverflowAnswer(2334, 545, List("code1"), List("tags1"))
)
}
}

0 comments on commit 218dedc

Please sign in to comment.