Skip to content

Markdown parsing bug search #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 11, 2019
Merged
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
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/bash -ex
PASSED_COUNT=33
PASSED_COUNT=34
FAILED_COUNT=2
TODO_COUNT=1

Expand Down
2 changes: 1 addition & 1 deletion src/VerifyExamples.elm
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ compileMarkdown : MarkdownSource -> Markdown.Parsed -> List Compiler.Result
compileMarkdown { fileName } parsed =
List.concatMap
(Markdown.compile fileName)
parsed.testSuites
(List.indexedMap Tuple.pair parsed.testSuites)



Expand Down
12 changes: 6 additions & 6 deletions src/VerifyExamples/Markdown.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ parse fileText =
|> Parsed


compile : String -> TestSuite -> List Compiler.Result
compile filePath suite =
compile : String -> ( Int, TestSuite ) -> List Compiler.Result
compile filePath ( suiteIndex, suite ) =
Compiler.compile
{ testModuleName = testModuleName filePath
{ testModuleName = testModuleName suiteIndex filePath
, testName = \test -> "Documentation VerifyExamples"
}
suite
Expand All @@ -36,16 +36,16 @@ toTestSuite (Snippet snippet) =
Parser.parse { snippet = snippet, functionName = Nothing }


testModuleName : String -> Int -> Test -> ModuleName
testModuleName filePath index _ =
testModuleName : Int -> String -> Int -> Test -> ModuleName
testModuleName suiteIndex filePath fileIndex _ =
let
filePathComponents =
filePath
|> Regex.replace (Regex.fromString "\\.md$" |> Maybe.withDefault Regex.never) (always "")
|> String.split "/"

addIndex components =
List.append components [ "Test" ++ String.fromInt index ]
List.append components [ "Test_" ++ String.fromInt fileIndex ++ "_" ++ String.fromInt suiteIndex ]
in
filePathComponents
|> List.map capitalizeFirst
Expand Down
3 changes: 3 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/elm-stuff/
# TODO: this is going to be a problem in the future with more tests for the
# VerifyExamples code. The test harness should create a sample
# `tests`directory elsewhere for CLI testing.
VerifyExamples
62 changes: 62 additions & 0 deletions tests/VerifyExamples/Markdown/SnippetTest.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module VerifyExamples.Markdown.SnippetTest exposing (..)

import Expect
import Test exposing (..)
import VerifyExamples.Markdown.Snippet as Snippet exposing (Snippet(..))


parseTest : Test
parseTest =
describe "parse"
[ test "on a single snippet" <|
\_ ->
Snippet.parse
"""Hello, World

```elm
1 + 2
--> 3
```

Goodbye world."""
|> Expect.equal [ Snippet "1 + 2\n--> 3" ]
, test "on multiple snippets" <|
\_ ->
Snippet.parse
"""Hello, World

```elm
1 + 2
--> 3
```

```elm
String.reverse "racecar"
--> "racecar"
```

Goodbye world."""
|> Expect.equal
[ Snippet "1 + 2\n--> 3"
, Snippet "String.reverse \"racecar\"\n--> \"racecar\""
]
, test "on a snippet that defines a function" <|
\_ ->
Snippet.parse
"""Hello, World

```elm
add : Int -> Int -> Int
add x y =
x + y

add 1 2
--> 3
```


Goodbye world."""
|> Expect.equal
[ Snippet "add : Int -> Int -> Int\nadd x y =\n x + y\n\nadd 1 2\n--> 3"
]
]