Skip to content

Commit

Permalink
Adding custom expectations samples
Browse files Browse the repository at this point in the history
  • Loading branch information
flbulgarelli committed Sep 22, 2019
1 parent 365aa9b commit 0c38ecd
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
56 changes: 52 additions & 4 deletions docs/clispec.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,39 @@ $ mulang '
}
```

### With custom expectations

> For more information about EDL syntax see [EDL Spec](../edlspec)
```bash
$ mulang '
{
"sample" : {
"tag" : "CodeSample",
"language" : "JavaScript",
"content" : "function plusOne(x) { return x + 1 }"
},
"spec" : {
"customExpectations" : "expectation: declares function `plusOne` that (returns with math);\nexpectation: !declares variable with literal"
}
}
' | json_pp
{
"tag" : "AnalysisCompleted",
"smells" : [],
"expectationResults" : [
{
"result" : true,
"expectation" : {
"binding" : "*",
"inspection" : "Declares:x"
}
}
],
"signatures" : []
}
```

### With signature analysis

```bash
Expand All @@ -104,12 +137,27 @@ $ mulang '
}
' | json_pp
{
"expectationResults" : [],
"tag" : "AnalysisCompleted",
"intermediateLanguage" : null,
"smells" : [],
"signatures" : [
"-- foo x y"
"signatures" : [],
"expectationResults" : [
{
"expectation" : {
"binding" : "<<custom>>",
"inspection" : "E0"
},
"result" : true
},
{
"expectation" : {
"inspection" : "E1",
"binding" : "<<custom>>"
},
"result" : true
}
],
"tag" : "AnalysisCompleted"
"testResults" : []
}
```

Expand Down
10 changes: 10 additions & 0 deletions docs/js/trymulang.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ const examples = {
]
}
},
"custom": {
"sample" : {
"tag" : "CodeSample",
"language" : "JavaScript",
"content" : "function plusOne(x) { return x + 1 }"
},
"spec" : {
"customExpectations" : "expectation: declares function `plusOne` that (returns with math);\nexpectation: !declares variable with literal"
}
},
"signature": {
"sample": {
"tag": "CodeSample",
Expand Down
1 change: 1 addition & 0 deletions docs/try.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<option selected="selected"></option>
<option value="intransitive">With intransitive expectations</option>
<option value="unscoped">With unscoped expectations</option>
<option value="custom">With custom expectations</option>
<option value="signature">With signature analysis</option>
<option value="broken">With broken input</option>
<option value="AST">With AST as input</option>
Expand Down
18 changes: 18 additions & 0 deletions spec/AnalysisJsonSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ spec = describe "AnalysisJson" $ do

run json `shouldBe` analysis

it "works with custom expectations" $ do
let json = [text|
{
"sample" : {
"tag" : "CodeSample",
"language" : "JavaScript",
"content" : "function plusOne(x) { return x + 1 }"
},
"spec" : {
"customExpectations" : "expectation: declares function `plusOne` that (returns with math);\nexpectation: !declares variable with literal"
}
} |]
let analysis = Analysis (CodeSample JavaScript "function plusOne(x) { return x + 1 }")
(emptyAnalysisSpec {
customExpectations = Just "expectation: declares function `plusOne` that (returns with math);\nexpectation: !declares variable with literal" })

run json `shouldBe` analysis

it "works with signature analysis" $ do
let json = [text|
{
Expand Down

0 comments on commit 0c38ecd

Please sign in to comment.