-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
2 changed files
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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><<test>></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><<test1>></code></pre>" + | ||
"<pre class = 'sth'><code><<test2>></code></pre>" + | ||
"<pre class = 'sth'><code><<test3>></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")) | ||
) | ||
} | ||
} |