git.iko.soy/rowtype-yoga/purescript-docs-search
on master help sign in
Fix everything except toppoki tests
7ef455fVladimir Kalnitsky
package.json+2−1
@@ -1,5 +1,6 @@
1{
1{
2 "name": "purescript-docs-search",
2 "name": "purescript-docs-search",
3+ "type": "module",
3 "version": "0.0.11",
4 "version": "0.0.11",
4 "description": "Search frontend for the documentation generated by the PureScript compiler.",
5 "description": "Search frontend for the documentation generated by the PureScript compiler.",
5 "directories": {
6 "directories": {
@@ -19,7 +20,7 @@
19 "bundle-app": "spago bundle-app --no-build --no-install -m Docs.Search.App --to dist/docs-search-app.js",
20 "bundle-app": "spago bundle-app --no-build --no-install -m Docs.Search.App --to dist/docs-search-app.js",
20 "esbuild-app": "esbuild dist/docs-search-app.js --target=es2016 --bundle --minify --outfile=dist/docs-search-app.min.js && mv dist/docs-search-app.min.js dist/docs-search-app.js",
21 "esbuild-app": "esbuild dist/docs-search-app.js --target=es2016 --bundle --minify --outfile=dist/docs-search-app.min.js && mv dist/docs-search-app.min.js dist/docs-search-app.js",
21 "build-app": "npm run bundle-app && npm run esbuild-app",
22 "build-app": "npm run bundle-app && npm run esbuild-app",
22− "bundle-main": "spago bundle-app --no-build --no-install -m Docs.Search.Main --to dist/main.js",
23+ "bundle-main": "spago bundle-app --no-build --no-install --platform node -m Docs.Search.Main --to dist/main.js",
23 "esbuild-main": "esbuild dist/main.js --platform=node --bundle --minify --outfile=dist/main.min.js && mv dist/main.min.js dist/main.js",
24 "esbuild-main": "esbuild dist/main.js --platform=node --bundle --minify --outfile=dist/main.min.js && mv dist/main.min.js dist/main.js",
24 "add-shebang": "echo \"#!/usr/bin/env node\" > dist/purescript-docs-search && cat dist/main.js >> dist/purescript-docs-search",
25 "add-shebang": "echo \"#!/usr/bin/env node\" > dist/purescript-docs-search && cat dist/main.js >> dist/purescript-docs-search",
25 "chmod-main": "chmod +x dist/purescript-docs-search",
26 "chmod-main": "chmod +x dist/purescript-docs-search",
packages.dhall+47−27
@@ -1,8 +1,10 @@
1let mkPackage =
1let mkPackage =
2− https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.2-20190725/src/mkPackage.dhall sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57
2+ https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.2-20190725/src/mkPackage.dhall
3+ sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57
3
4
4let upstream =
5let upstream =
5− https://github.com/purescript/package-sets/releases/download/psc-0.14.0-20210409/packages.dhall sha256:e81c2f2ce790c0e0d79869d22f7a37d16caeb5bd81cfda71d46c58f6199fd33f
6+ https://github.com/purescript/package-sets/releases/download/psc-0.15.0-20220506/packages.dhall
7+ sha256:f83b68ff07cf6557e82379e749118e6ff11eecc6be5754540aae855cd1e46917
6
8
7let overrides = {=}
9let overrides = {=}
8
10
@@ -33,12 +35,7 @@ let additions =
33 , "web-uievents"
35 , "web-uievents"
34 ]
36 ]
35 "https://github.com/purescript-halogen/purescript-halogen.git"
37 "https://github.com/purescript-halogen/purescript-halogen.git"
36− "v6.1.0"
37− , halogen-css =
38− mkPackage
39− [ "halogen" ]
40− "https://github.com/slamdata/purescript-halogen-css.git"
41− "v8.0.0"
38+ "v7.0.0"
42 , memoize =
39 , memoize =
43 mkPackage
40 mkPackage
44 [ "prelude"
41 [ "prelude"
@@ -67,8 +64,8 @@ let additions =
67 , "free"
64 , "free"
68 , "memoize"
65 , "memoize"
69 ]
66 ]
70− "https://github.com/srghma/purescript-optparse.git"
67+ "https://github.com/klntsky/purescript-optparse.git"
71− "d49b03fcd35f5be167e9c5c44ab1c17ca0956fb1"
68+ "2fe4265b7c6b09744c11190a43ca06777c752473"
72 , exitcodes =
69 , exitcodes =
73 mkPackage
70 mkPackage
74 [ "enums" ]
71 [ "enums" ]
@@ -77,30 +74,42 @@ let additions =
77 , markdown-it =
74 , markdown-it =
78 mkPackage
75 mkPackage
79 [ "prelude", "effect", "options" ]
76 [ "prelude", "effect", "options" ]
80− "https://github.com/nonbili/purescript-markdown-it.git"
77+ "https://github.com/klntsky/purescript-markdown-it.git"
81− "v0.4.0"
78+ "f3b7654783a83a80d7c09b6caaa7cd40b93ddce1"
79+ , string-parsers =
80+ mkPackage
81+ [ "arrays"
82+ , "assert"
83+ , "bifunctors"
84+ , "console"
85+ , "control"
86+ , "effect"
87+ , "either"
88+ , "enums"
89+ , "foldable-traversable"
90+ , "lists"
91+ , "maybe"
92+ , "minibench"
93+ , "nonempty"
94+ , "partial"
95+ , "prelude"
96+ , "strings"
97+ , "tailrec"
98+ , "transformers"
99+ , "unfoldable"
100+ ]
101+ "https://github.com/purescript-contrib/purescript-string-parsers.git"
102+ "v8.0.0"
82 , html-parser-halogen =
103 , html-parser-halogen =
83 mkPackage
104 mkPackage
84 [ "string-parsers", "halogen" ]
105 [ "string-parsers", "halogen" ]
85− "https://github.com/rnons/purescript-html-parser-halogen.git"
106+ "https://github.com/klntsky/purescript-html-parser-halogen.git"
86− "458e492e441fcf69a66911b7b64beea5849e0dad"
107+ "5c31890d060d5abd0038fed6acd3f999a9362369"
87 , markdown-it-halogen =
108 , markdown-it-halogen =
88 mkPackage
109 mkPackage
89 [ "markdown-it", "html-parser-halogen" ]
110 [ "markdown-it", "html-parser-halogen" ]
90 "https://github.com/nonbili/purescript-markdown-it-halogen.git"
111 "https://github.com/nonbili/purescript-markdown-it-halogen.git"
91 "08c9625015bf04214be14e45230e8ce12f3fa2bf"
112 "08c9625015bf04214be14e45230e8ce12f3fa2bf"
92− , toppokki =
93− mkPackage
94− [ "prelude"
95− , "record"
96− , "functions"
97− , "node-http"
98− , "aff-promise"
99− , "node-buffer"
100− , "node-fs-aff"
101− ]
102− "https://github.com/justinwoo/purescript-toppokki.git"
103− "v2.4.0"
104 , search-trie =
113 , search-trie =
105 mkPackage
114 mkPackage
106 [ "prelude"
115 [ "prelude"
@@ -126,7 +135,18 @@ let additions =
126 , "transformers"
135 , "transformers"
127 ]
136 ]
128 "https://github.com/purescript-contrib/purescript-css.git"
137 "https://github.com/purescript-contrib/purescript-css.git"
129− "5c1a44ee95c259352a2b4570b060de14130540bc"
138+ "710d6a742beb88299faf08aaeb997ee1e24483ab"
139+ , jest =
140+ mkPackage
141+ [ "aff"
142+ , "aff-promise"
143+ , "effect"
144+ , "prelude"
145+ , "psci-support"
146+ , "foldable-traversable"
147+ ]
148+ "https://github.com/klntsky/purescript-jest.git"
149+ "7feaa5a880fc75002c4eca312993174e7220252b"
130 }
150 }
131
151
132in upstream // overrides // additions
152in upstream // overrides // additions
spago.dhall+1−2
@@ -39,10 +39,9 @@
39 , "profunctor"
39 , "profunctor"
40 , "profunctor-lenses"
40 , "profunctor-lenses"
41 , "search-trie"
41 , "search-trie"
42+ , "spec"
42 , "string-parsers"
43 , "string-parsers"
43 , "strings"
44 , "strings"
44− , "test-unit"
45− , "toppokki"
46 , "transformers"
45 , "transformers"
47 , "tuples"
46 , "tuples"
48 , "unfoldable"
47 , "unfoldable"
src/Docs/Search/App.purs+5−5
@@ -86,7 +86,7 @@ main = do
86 srio <- runUI resultsComponent unit searchResults
86 srio <- runUI resultsComponent unit searchResults
87
87
88 void $ H.liftEffect $ subscribe sfio.messages $ \sfm -> do
88 void $ H.liftEffect $ subscribe sfio.messages $ \sfm -> do
89− launchAff_ do
89+ launchAff_ $ void do
90 srio.query (SearchResults.MessageFromSearchField sfm unit)
90 srio.query (SearchResults.MessageFromSearchField sfm unit)
91
91
92 -- We need to read the URI hash only when both components are initialized and
92 -- We need to read the URI hash only when both components are initialized and
@@ -97,8 +97,8 @@ main = do
97 H.liftEffect do
97 H.liftEffect do
98
98
99 listener <-
99 listener <-
100− eventListener \event ->
100+ eventListener \_event ->
101− launchAff_ do
101+ launchAff_ $ void do
102 sfio.query $ SearchField.ReadURIHash unit
102 sfio.query $ SearchField.ReadURIHash unit
103
103
104 addEventListener hashchange listener true (Window.toEventTarget window)
104 addEventListener hashchange listener true (Window.toEventTarget window)
@@ -111,8 +111,8 @@ main = do
111 H.liftEffect do
111 H.liftEffect do
112
112
113 listener <-
113 listener <-
114− eventListener \event ->
114+ eventListener \_event ->
115− launchAff_ do
115+ launchAff_ $ void do
116 sbio.query $ Sidebar.UpdateModuleGrouping unit
116 sbio.query $ Sidebar.UpdateModuleGrouping unit
117
117
118 addEventListener focus listener true (Window.toEventTarget window)
118 addEventListener focus listener true (Window.toEventTarget window)
src/Docs/Search/App/SearchField.purs+1−1
@@ -156,7 +156,7 @@ render state =
156 [ HH.input
156 [ HH.input
157 [ HP.value state.input
157 [ HP.value state.input
158 , HP.placeholder "Search for definitions... (S to focus)"
158 , HP.placeholder "Search for definitions... (S to focus)"
159− , HP.id_ "docs-search-query-field"
159+ , HP.id "docs-search-query-field"
160 , HP.type_ HP.InputText
160 , HP.type_ HP.InputText
161 , HE.onKeyUp (\event ->
161 , HE.onKeyUp (\event ->
162 case KeyboardEvent.code event of
162 case KeyboardEvent.code event of
src/Docs/Search/App/SearchResults.purs+2−2
@@ -202,9 +202,9 @@ render state@{ mode: Active } =
202 , HH.div_ $
202 , HH.div_ $
203 Array.concat $ shownResults <#> renderResult state
203 Array.concat $ shownResults <#> renderResult state
204
204
205− , HH.div [ HP.class_ (wrap "load_more"), HP.id_ "load-more" ]
205+ , HH.div [ HP.class_ (wrap "load_more"), HP.id "load-more" ]
206 [ if Array.length shownResults < Array.length state.results
206 [ if Array.length shownResults < Array.length state.results
207− then HH.a [ HP.id_ "load-more-link"
207+ then HH.a [ HP.id "load-more-link"
208 , HE.onClick $ const MoreResultsRequested ]
208 , HE.onClick $ const MoreResultsRequested ]
209 [ HH.text "Show more results" ]
209 [ HH.text "Show more results" ]
210 else HH.p_
210 else HH.p_
src/Docs/Search/App/Sidebar.purs+4−4
@@ -17,7 +17,6 @@ import Data.Maybe (Maybe(..), isJust, fromMaybe)
17import Data.Newtype (wrap, unwrap)
17import Data.Newtype (wrap, unwrap)
18import Data.Set (Set)
18import Data.Set (Set)
19import Data.Set as Set
19import Data.Set as Set
20−import Data.Symbol (SProxy(..))
21import Data.Tuple.Nested (type (/\), (/\))
20import Data.Tuple.Nested (type (/\), (/\))
22import Effect (Effect)
21import Effect (Effect)
23import Effect.Aff (Aff)
22import Effect.Aff (Aff)
@@ -25,6 +24,7 @@ import Halogen as H
25import Halogen.HTML as HH
24import Halogen.HTML as HH
26import Halogen.HTML.Events as HE
25import Halogen.HTML.Events as HE
27import Halogen.HTML.Properties as HP
26import Halogen.HTML.Properties as HP
27+import Type.Proxy (Proxy(..))
28import Web.HTML as HTML
28import Web.HTML as HTML
29import Web.HTML.Window as Window
29import Web.HTML.Window as Window
30import Web.Storage.Storage as Storage
30import Web.Storage.Storage as Storage
@@ -131,7 +131,7 @@ render state@{ groupingMode, moduleNames, localPackageName } =
131 ]
131 ]
132
132
133 [ HH.h3_ [ HH.text $ if groupingMode == DontGroup then "Modules" else "Packages" ]
133 [ HH.h3_ [ HH.text $ if groupingMode == DontGroup then "Modules" else "Packages" ]
134− , HH.input [ HP.id_ "group-modules__input"
134+ , HH.input [ HP.id "group-modules__input"
135 , HP.type_ HP.InputCheckbox
135 , HP.type_ HP.InputCheckbox
136 , HP.checked (groupingMode == GroupByPackage)
136 , HP.checked (groupingMode == GroupByPackage)
137 , HE.onChecked $ ToggleGrouping <<< isCheckedToGroupingMode
137 , HE.onChecked $ ToggleGrouping <<< isCheckedToGroupingMode
@@ -139,7 +139,7 @@ render state@{ groupingMode, moduleNames, localPackageName } =
139
139
140 , HH.text " "
140 , HH.text " "
141 , HH.label [ HP.for "group-modules__input"
141 , HH.label [ HP.for "group-modules__input"
142− , HP.id_ "group-modules__label"
142+ , HP.id "group-modules__label"
143 ]
143 ]
144 [ HH.text " GROUP BY PACKAGE" ]
144 [ HH.text " GROUP BY PACKAGE" ]
145
145
@@ -215,4 +215,4 @@ isCheckedToGroupingMode = if _ then GroupByPackage else DontGroup
215-- Some optics:
215-- Some optics:
216
216
217_groupingMode :: forall a b rest. (a -> b) -> { groupingMode :: a | rest } -> { groupingMode :: b | rest }
217_groupingMode :: forall a b rest. (a -> b) -> { groupingMode :: a | rest } -> { groupingMode :: b | rest }
218−_groupingMode = prop (SProxy :: SProxy "groupingMode")
218+_groupingMode = prop (Proxy :: Proxy "groupingMode")
src/Docs/Search/BrowserEngine.js+1−1
@@ -1,6 +1,6 @@
1/* global exports */
1/* global exports */
2
2
3−exports.loadIndex_ = function (partId) {
3+export function loadIndex_ (partId) {
4 return function (url) {
4 return function (url) {
5 return function () {
5 return function () {
6 return new Promise(function(resolve, reject) {
6 return new Promise(function(resolve, reject) {
src/Docs/Search/IndexBuilder.js+4−5
@@ -1,14 +1,13 @@
1/* global __dirname require exports */
1/* global __dirname require exports */
2
2
3−var path = require('path');
3+import globMain from "glob";
4−var glob = require('glob');
5
4
6−exports.getDirname = function () {
5+export function getDirname () {
7 return __dirname;
6 return __dirname;
8};
7};
9
8
10−exports.glob = function (pattern) {
9+export function glob (pattern) {
11 return function () {
10 return function () {
12− return glob.sync(pattern);
11+ return globMain.sync(pattern);
13 };
12 };
14};
13};
src/Docs/Search/IndexBuilder.purs+4−3
@@ -43,7 +43,8 @@ import Effect.Aff (Aff, launchAff_, parallel, sequential)
43import Effect.Class (liftEffect)
43import Effect.Class (liftEffect)
44import Effect.Console (log)
44import Effect.Console (log)
45import Node.Encoding (Encoding(UTF8))
45import Node.Encoding (Encoding(UTF8))
46−import Node.FS.Aff (exists, mkdir, readFile, readTextFile, readdir, stat, writeFile, writeTextFile)
46+import Node.FS.Aff (mkdir, readFile, readTextFile, readdir, stat, writeFile, writeTextFile)
47+import Node.FS.Sync (exists)
47import Node.FS.Stats (isDirectory, isFile)
48import Node.FS.Stats (isDirectory, isFile)
48import Node.Process as Process
49import Node.Process as Process
49import Web.Bower.PackageMeta (PackageMeta(..))
50import Web.Bower.PackageMeta (PackageMeta(..))
@@ -369,7 +370,7 @@ copyAppFile { generatedDocs } = do
369
370
370directoryExists :: String -> Aff Boolean
371directoryExists :: String -> Aff Boolean
371directoryExists path = do
372directoryExists path = do
372− doesExist <- exists path
373+ doesExist <- liftEffect $ exists path
373 case doesExist of
374 case doesExist of
374 false -> pure false
375 false -> pure false
375 true -> isDirectory <$> stat path
376 true -> isDirectory <$> stat path
@@ -377,7 +378,7 @@ directoryExists path = do
377
378
378fileExists :: String -> Aff Boolean
379fileExists :: String -> Aff Boolean
379fileExists path = do
380fileExists path = do
380− doesExist <- exists path
381+ doesExist <- liftEffect $ exists path
381 case doesExist of
382 case doesExist of
382 false -> pure false
383 false -> pure false
383 true -> isFile <$> stat path
384 true -> isFile <$> stat path
src/Docs/Search/Loader.js+1−1
@@ -1,6 +1,6 @@
1/* global exports */
1/* global exports */
2
2
3−exports.loadFromScript = function (globalIdentifier) {
3+export function loadFromScript (globalIdentifier) {
4 return function (url) {
4 return function (url) {
5 return function () {
5 return function () {
6 return new Promise(function (resolve, reject) {
6 return new Promise(function (resolve, reject) {
src/Docs/Search/ModuleIndex.js+1−1
@@ -1,6 +1,6 @@
1/* global exports */
1/* global exports */
2
2
3−exports.load = function (url) {
3+export function load (url) {
4 return function () {
4 return function () {
5 return new Promise(function (resolve, reject) {
5 return new Promise(function (resolve, reject) {
6 if (typeof window.DocsSearchModuleIndex === 'undefined') {
6 if (typeof window.DocsSearchModuleIndex === 'undefined') {
src/Docs/Search/ModuleIndex.purs+3−4
@@ -30,12 +30,11 @@ import Data.Set as Set
30import Data.String.CodeUnits (toCharArray) as String
30import Data.String.CodeUnits (toCharArray) as String
31import Data.String.Common (split, toLower) as String
31import Data.String.Common (split, toLower) as String
32import Data.String.Pattern (Pattern(..))
32import Data.String.Pattern (Pattern(..))
33−import Data.Symbol (SProxy(..))
34import Data.Traversable (foldr, for_)
33import Data.Traversable (foldr, for_)
35import Data.Tuple.Nested ((/\))
34import Data.Tuple.Nested ((/\))
36import Effect (Effect)
35import Effect (Effect)
37import Effect.Aff (Aff)
36import Effect.Aff (Aff)
38−
37+import Type.Proxy (Proxy(..))
39
38
40-- | Module index that is actually stored in a JS file.
39-- | Module index that is actually stored in a JS file.
41type PackedModuleIndex = Map PackageInfo (Set ModuleName)
40type PackedModuleIndex = Map PackageInfo (Set ModuleName)
@@ -116,7 +115,7 @@ foreign import load
116
115
117
116
118_modulePackages :: forall a b rest. (a -> b) -> { modulePackages :: a | rest } -> { modulePackages :: b | rest }
117_modulePackages :: forall a b rest. (a -> b) -> { modulePackages :: a | rest } -> { modulePackages :: b | rest }
119−_modulePackages = prop (SProxy :: SProxy "modulePackages")
118+_modulePackages = prop (Proxy :: Proxy "modulePackages")
120
119
121_index :: forall a b rest. (a -> b) -> { index :: a | rest } -> { index :: b | rest }
120_index :: forall a b rest. (a -> b) -> { index :: a | rest } -> { index :: b | rest }
122−_index = prop (SProxy :: SProxy "index")
121+_index = prop (Proxy :: Proxy "index")
src/Docs/Search/TypeIndex.js+1−1
@@ -1,6 +1,6 @@
1/* global exports */
1/* global exports */
2
2
3−exports.lookup_ = function (shape) {
3+export function lookup_ (shape) {
4 return function (url) {
4 return function (url) {
5 return function () {
5 return function () {
6 return new Promise(function (resolve, reject) {
6 return new Promise(function (resolve, reject) {
src/Docs/Search/TypeQuery.purs+3−3
@@ -34,9 +34,9 @@ import Data.Set as Set
34import Data.String.CodeUnits (fromCharArray)
34import Data.String.CodeUnits (fromCharArray)
35import Data.String.Common (trim) as String
35import Data.String.Common (trim) as String
36import Data.Tuple (Tuple(..), fst, snd)
36import Data.Tuple (Tuple(..), fst, snd)
37−import Text.Parsing.StringParser (ParseError, Parser, runParser, try)
37+import StringParser (ParseError, Parser, runParser, try)
38−import Text.Parsing.StringParser.CodePoints (alphaNum, anyLetter, char, eof, lowerCaseChar, skipSpaces, string, upperCaseChar)
38+import StringParser.CodePoints (alphaNum, anyLetter, char, eof, lowerCaseChar, skipSpaces, string, upperCaseChar)
39−import Text.Parsing.StringParser.Combinators (fix, sepBy, sepBy1, sepEndBy, sepEndBy1)
39+import StringParser.Combinators (fix, sepBy, sepBy1, sepEndBy, sepEndBy1)
40
40
41
41
42-- | We need type queries because we don't have a full-featured type parser
42-- | We need type queries because we don't have a full-featured type parser
src/Docs/Search/TypeShape.js+1−1
@@ -1,6 +1,6 @@
1/* global exports */
1/* global exports */
2
2
3−exports.hash = function (string) {
3+export function hash (string) {
4 var hash = Math.floor(Number.MAX_SAFE_INTEGER / 2);
4 var hash = Math.floor(Number.MAX_SAFE_INTEGER / 2);
5 if (string.length == 0) {
5 if (string.length == 0) {
6 return hash;
6 return hash;
src/Docs/Search/URIHash.js+1−1
@@ -1,7 +1,7 @@
1/* global exports history */
1/* global exports history */
2
2
3// https://stackoverflow.com/questions/1397329
3// https://stackoverflow.com/questions/1397329
4−exports.removeHash = function () {
4+export function removeHash () {
5 var scrollV, scrollH, loc = window.location;
5 var scrollV, scrollH, loc = window.location;
6 if ("pushState" in history)
6 if ("pushState" in history)
7 history.pushState("", document.title, loc.pathname + loc.search);
7 history.pushState("", document.title, loc.pathname + loc.search);
src/Docs/Search/URIHash.purs+2−2
@@ -7,7 +7,7 @@ where
7
7
8import Prelude
8import Prelude
9
9
10−import Data.Maybe (Maybe(Just), fromMaybe)
10+import Data.Maybe (fromMaybe)
11import Data.String.CodeUnits as String
11import Data.String.CodeUnits as String
12import Effect (Effect)
12import Effect (Effect)
13import JSURI (decodeURIComponent, encodeURIComponent)
13import JSURI (decodeURIComponent, encodeURIComponent)
@@ -31,7 +31,7 @@ getInput = do
31 location <- Window.location window
31 location <- Window.location window
32 hash <- Location.hash location
32 hash <- Location.hash location
33 pure $
33 pure $
34− if String.slice 0 8 hash == Just "#search:"
34+ if String.slice 0 8 hash == "#search:"
35 then fromMaybe "" $
35 then fromMaybe "" $
36 decodeURIComponent $
36 decodeURIComponent $
37 String.drop 8 hash
37 String.drop 8 hash
test/Main.purs+6−4
@@ -9,15 +9,17 @@ import Test.ModuleIndex as ModuleIndex
9import Test.TypeQuery as TypeQuery
9import Test.TypeQuery as TypeQuery
10import Test.TypeJson as TypeJson
10import Test.TypeJson as TypeJson
11import Test.UI as UI
11import Test.UI as UI
12−import Test.Unit (TestSuite)
12+import Test.Spec (Spec)
13−import Test.Unit.Main (runTest)
13+import Test.Spec.Reporter.Console (consoleReporter)
14+import Test.Spec.Runner (runSpec)
15+import Effect.Aff (launchAff_)
14
16
15main :: Effect Unit
17main :: Effect Unit
16main = do
18main = do
17− runTest mainTest
19+ launchAff_ $ runSpec [consoleReporter] mainTest
18 UI.main
20 UI.main
19
21
20−mainTest :: TestSuite
22+mainTest :: Spec Unit
21mainTest = do
23mainTest = do
22 TypeQuery.tests
24 TypeQuery.tests
23 TypeJson.tests
25 TypeJson.tests
test/Test/Declarations.purs+12−13
@@ -7,33 +7,32 @@ import Docs.Search.Types (PackageName(..), PackageInfo(..))
7
7
8import Data.Maybe (Maybe(..))
8import Data.Maybe (Maybe(..))
9import Data.Newtype (wrap)
9import Data.Newtype (wrap)
10+import Test.Spec (Spec, describe, it)
11+import Test.Spec.Assertions (shouldEqual)
10
12
11−import Test.Unit (TestSuite, suite, test)
13+tests :: Spec Unit
12−import Test.Unit.Assert as Assert
13−
14−tests :: TestSuite
15tests = do
14tests = do
16− suite "Declarations" do
15+ describe "Declarations" do
17− test "extractPackageName" do
16+ it "extractPackageName works correctly" do
18− Assert.equal Builtin (extractPackageName (wrap "Prim") Nothing)
17+ Builtin `shouldEqual` (extractPackageName (wrap "Prim") Nothing)
19− Assert.equal Builtin (extractPackageName (wrap "Prim.Foo") Nothing)
18+ Builtin `shouldEqual` (extractPackageName (wrap "Prim.Foo") Nothing)
20− Assert.equal Builtin (extractPackageName (wrap "Prim.Foo.Bar") Nothing)
19+ Builtin `shouldEqual` (extractPackageName (wrap "Prim.Foo.Bar") Nothing)
21− Assert.equal UnknownPackage (extractPackageName (wrap "Primitive") Nothing)
20+ UnknownPackage `shouldEqual` (extractPackageName (wrap "Primitive") Nothing)
22− Assert.equal (Package $ PackageName "foo")
21+ Package (PackageName "foo") `shouldEqual`
23 (extractPackageName (wrap "Foo") $
22 (extractPackageName (wrap "Foo") $
24 Just { start: []
23 Just { start: []
25 , end: []
24 , end: []
26 , name: ".spago/foo/src/Foo.purs"
25 , name: ".spago/foo/src/Foo.purs"
27 }
26 }
28 )
27 )
29− Assert.equal (Package $ PackageName "bar")
28+ Package (PackageName "bar") `shouldEqual`
30 (extractPackageName (wrap "Bar") $
29 (extractPackageName (wrap "Bar") $
31 Just { start: []
30 Just { start: []
32 , end: []
31 , end: []
33 , name: "/path/to/somewhere/bower_components/bar/src/Bar.purs"
32 , name: "/path/to/somewhere/bower_components/bar/src/Bar.purs"
34 }
33 }
35 )
34 )
36− Assert.equal LocalPackage
35+ LocalPackage `shouldEqual`
37 (extractPackageName (wrap "Bar") $
36 (extractPackageName (wrap "Bar") $
38 Just { start: []
37 Just { start: []
39 , end: []
38 , end: []
test/Test/Extra.purs+6−5
@@ -4,7 +4,8 @@ import Prelude
4
4
5import Data.Either (Either(..))
5import Data.Either (Either(..))
6import Effect.Aff (Aff)
6import Effect.Aff (Aff)
7−import Test.Unit.Assert as Assert
7+import Test.Spec.Assertions (shouldEqual)
8+
8
9
9assertRight
10assertRight
10 :: forall a b
11 :: forall a b
@@ -17,7 +18,7 @@ assertRight
17 -> Aff Unit
18 -> Aff Unit
18assertRight eiActual expected =
19assertRight eiActual expected =
19 case eiActual of
20 case eiActual of
20− Left string -> do
21+ Left _ -> do
21− Assert.equal (Right expected) eiActual
22+ Right expected `shouldEqual` eiActual
22− Right actual -> do
23+ Right _ -> do
23− Assert.equal (Right expected) eiActual
24+ Right expected `shouldEqual` eiActual
test/Test/IndexBuilder.purs+9−9
@@ -5,16 +5,16 @@ import Prelude
5import Docs.Search.IndexBuilder (patchHTML)
5import Docs.Search.IndexBuilder (patchHTML)
6
6
7import Data.Tuple (snd)
7import Data.Tuple (snd)
8−import Test.Unit (TestSuite, suite, test)
8+import Test.Spec (Spec, describe, it)
9−import Test.Unit.Assert as Assert
9+import Test.Spec.Assertions (shouldEqual, shouldNotSatisfy)
10
10
11−tests :: TestSuite
11+tests :: Spec Unit
12tests = do
12tests = do
13− suite "IndexBuilder" do
13+ describe "IndexBuilder" do
14− suite "patchHTML" do
14+ describe "patchHTML" do
15− test "works" do
15+ it "works" do
16 let input = "</body>"
16 let input = "</body>"
17− Assert.assertFalse "patchHTML works" (snd (patchHTML input) == input)
17+ shouldNotSatisfy (snd (patchHTML input)) (eq input)
18− test "is idempotent" do
18+ it "is idempotent" do
19 let input = "</body>"
19 let input = "</body>"
20− Assert.equal (snd $ patchHTML $ snd $ patchHTML input) (snd $ patchHTML input)
20+ shouldEqual (snd $ patchHTML $ snd $ patchHTML input) (snd $ patchHTML input)
test/Test/ModuleIndex.purs+8−10
@@ -6,20 +6,18 @@ import Prelude
6
6
7import Data.List as List
7import Data.List as List
8import Data.Newtype (wrap)
8import Data.Newtype (wrap)
9−import Test.Unit (TestSuite, suite, test)
9+import Test.Spec (Spec, describe, it)
10−import Test.Unit.Assert as Assert
10+import Test.Spec.Assertions (shouldEqual)
11
11
12
12
13−tests :: TestSuite
13+tests :: Spec Unit
14tests = do
14tests = do
15− suite "ModuleIndex" do
15+ describe "ModuleIndex" do
16
16
17− test "test #0" do
17+ it "test #0" do
18− Assert.equal (extractModuleNameParts $ wrap "Data.Array.ST") (
18+ extractModuleNameParts (wrap "Data.Array.ST") `shouldEqual`
19 List.fromFoldable [ "st", "array.st", "data.array.st" ]
19 List.fromFoldable [ "st", "array.st", "data.array.st" ]
20− )
21
20
22− test "test #1" do
21+ it "test #1" do
23− Assert.equal (extractModuleNameParts $ wrap "Foo") (
22+ extractModuleNameParts (wrap "Foo") `shouldEqual`
24 List.fromFoldable [ "foo" ]
23 List.fromFoldable [ "foo" ]
25− )
test/Test/TypeJson.purs+18−18
@@ -15,13 +15,13 @@ import Data.Argonaut.Parser (jsonParser)
15import Data.Either (Either(..))
15import Data.Either (Either(..))
16import Data.Maybe (Maybe(..))
16import Data.Maybe (Maybe(..))
17import Partial.Unsafe (unsafePartial)
17import Partial.Unsafe (unsafePartial)
18−import Test.Unit (TestSuite, suite, test)
18+import Test.Spec (Spec, describe, it)
19
19
20
20
21−tests :: TestSuite
21+tests :: Spec Unit
22tests = do
22tests = do
23− suite "FunDeps decoder" do
23+ describe "FunDeps decoder" do
24− test "FunDeps" do
24+ it "FunDeps" do
25 let
25 let
26 funDeps = mkJson """
26 funDeps = mkJson """
27 [
27 [
@@ -42,8 +42,8 @@ tests = do
42 }
42 }
43 ])
43 ])
44
44
45− suite "Constraint decoder" do
45+ describe "Constraint decoder" do
46− test "Constraint" do
46+ it "Constraint" do
47 let constraint = mkJson """
47 let constraint = mkJson """
48 {
48 {
49 "constraintAnn": [],
49 "constraintAnn": [],
@@ -62,8 +62,8 @@ tests = do
62 , constraintArgs: []
62 , constraintArgs: []
63 })
63 })
64
64
65− suite "Type decoder" do
65+ describe "Type decoder" do
66− test "TypeVar" do
66+ it "TypeVar" do
67 let typeVar = mkJson """
67 let typeVar = mkJson """
68 {
68 {
69 "annotation": [],
69 "annotation": [],
@@ -75,7 +75,7 @@ tests = do
75 assertRight (decodeJson typeVar)
75 assertRight (decodeJson typeVar)
76 (TypeVar "m")
76 (TypeVar "m")
77
77
78− test "TypeApp" do
78+ it "TypeApp" do
79 let typeApp1 = mkJson """
79 let typeApp1 = mkJson """
80 {
80 {
81 "annotation": [],
81 "annotation": [],
@@ -114,7 +114,7 @@ tests = do
114 ))
114 ))
115 (TypeVar "h")
115 (TypeVar "h")
116
116
117− test "TypeOp" do
117+ it "TypeOp" do
118 let typeOp = mkJson """
118 let typeOp = mkJson """
119 {
119 {
120 "annotation": [],
120 "annotation": [],
@@ -131,7 +131,7 @@ tests = do
131 assertRight (decodeJson typeOp) $
131 assertRight (decodeJson typeOp) $
132 TypeOp $ qualified [ "Data", "NaturalTransformation" ] "~>"
132 TypeOp $ qualified [ "Data", "NaturalTransformation" ] "~>"
133
133
134− test "BinaryNoParens" do
134+ it "BinaryNoParens" do
135 let binaryNoParens = mkJson """
135 let binaryNoParens = mkJson """
136 {
136 {
137 "annotation": [],
137 "annotation": [],
@@ -168,7 +168,7 @@ tests = do
168 (TypeVar "m")
168 (TypeVar "m")
169 (TypeVar "n")
169 (TypeVar "n")
170
170
171− test "ParensInType" do
171+ it "ParensInType" do
172 let parensInType = mkJson """
172 let parensInType = mkJson """
173 {
173 {
174 "annotation": [],
174 "annotation": [],
@@ -208,7 +208,7 @@ tests = do
208 TypeApp
208 TypeApp
209 (TypeConstructor (qualified [ "Data", "Maybe" ] "Maybe"))
209 (TypeConstructor (qualified [ "Data", "Maybe" ] "Maybe"))
210 (TypeConstructor (qualified [ "Prim" ] "String"))
210 (TypeConstructor (qualified [ "Prim" ] "String"))
211− test "RCons" do
211+ it "RCons" do
212
212
213 let rcons = mkJson """
213 let rcons = mkJson """
214 {
214 {
@@ -253,7 +253,7 @@ tests = do
253 (TypeVar "t"))
253 (TypeVar "t"))
254 REmpty
254 REmpty
255
255
256− test "ForAll #1" do
256+ it "ForAll #1" do
257 let forallJson = mkJson """
257 let forallJson = mkJson """
258 {"annotation":[],"tag":"ForAll","contents":["a",{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"String"]}]},{"annotation":[],"tag":"TypeVar","contents":"a"}]},null]}
258 {"annotation":[],"tag":"ForAll","contents":["a",{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"String"]}]},{"annotation":[],"tag":"TypeVar","contents":"a"}]},null]}
259 """
259 """
@@ -262,13 +262,13 @@ tests = do
262 (TypeConstructor $ qualified ["Prim"] "String"))
262 (TypeConstructor $ qualified ["Prim"] "String"))
263 (TypeVar "a"))
263 (TypeVar "a"))
264
264
265− test "KindApp" do
265+ it "KindApp" do
266 let kindAppJson = mkJson """
266 let kindAppJson = mkJson """
267 {"annotation":[],"tag":"KindApp","contents":[{"annotation":[],"tag":"REmpty"},{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Type"]}]}
267 {"annotation":[],"tag":"KindApp","contents":[{"annotation":[],"tag":"REmpty"},{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Type"]}]}
268 """
268 """
269 assertRight (decodeJson kindAppJson) $
269 assertRight (decodeJson kindAppJson) $
270 KindApp REmpty (TypeConstructor (qualified ["Prim"] "Type"))
270 KindApp REmpty (TypeConstructor (qualified ["Prim"] "Type"))
271− test "KindedType" do
271+ it "KindedType" do
272 let kindedTypeJson = mkJson """
272 let kindedTypeJson = mkJson """
273 {"annotation":[],"tag":"KindedType","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Data","Const"],"Const"]},{"annotation":[],"tag":"TypeConstructor","contents":[["Data","Void"],"Void"]}]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Type"]}]},{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Type"]}]}]}
273 {"annotation":[],"tag":"KindedType","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Data","Const"],"Const"]},{"annotation":[],"tag":"TypeConstructor","contents":[["Data","Void"],"Void"]}]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Type"]}]},{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Type"]}]}]}
274 """
274 """
@@ -281,9 +281,9 @@ tests = do
281 (TypeConstructor (qualified ["Prim"] "Function"))
281 (TypeConstructor (qualified ["Prim"] "Function"))
282 (TypeConstructor (qualified ["Prim"] "Type" )))
282 (TypeConstructor (qualified ["Prim"] "Type" )))
283 (TypeConstructor (qualified ["Prim"] "Type")))
283 (TypeConstructor (qualified ["Prim"] "Type")))
284− suite "jsons" do
284+ describe "jsons" do
285
285
286− test "jsons #1" do
286+ it "jsons #1" do
287 let json = mkJson """
287 let json = mkJson """
288{"annotation":[],"tag":"ForAll","contents":["o",{"annotation":[],"tag":"ForAll","contents":["r",{"annotation":[],"tag":"ForAll","contents":["l",{"annotation":[],"tag":"ConstrainedType","contents":[{"constraintAnn":[],"constraintClass":[["Type","Data","Boolean"],"And"],"constraintArgs":[{"annotation":[],"tag":"TypeVar","contents":"l"},{"annotation":[],"tag":"TypeVar","contents":"r"},{"annotation":[],"tag":"TypeVar","contents":"o"}],"constraintData":null},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Type","Data","Boolean"],"BProxy"]},{"annotation":[],"tag":"TypeVar","contents":"l"}]}]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Type","Data","Boolean"],"BProxy"]},{"annotation":[],"tag":"TypeVar","contents":"r"}]}]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Type","Data","Boolean"],"BProxy"]},{"annotation":[],"tag":"TypeVar","contents":"o"}]}]}]}]},null]},null]},null]}
288{"annotation":[],"tag":"ForAll","contents":["o",{"annotation":[],"tag":"ForAll","contents":["r",{"annotation":[],"tag":"ForAll","contents":["l",{"annotation":[],"tag":"ConstrainedType","contents":[{"constraintAnn":[],"constraintClass":[["Type","Data","Boolean"],"And"],"constraintArgs":[{"annotation":[],"tag":"TypeVar","contents":"l"},{"annotation":[],"tag":"TypeVar","contents":"r"},{"annotation":[],"tag":"TypeVar","contents":"o"}],"constraintData":null},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Type","Data","Boolean"],"BProxy"]},{"annotation":[],"tag":"TypeVar","contents":"l"}]}]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Type","Data","Boolean"],"BProxy"]},{"annotation":[],"tag":"TypeVar","contents":"r"}]}]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Type","Data","Boolean"],"BProxy"]},{"annotation":[],"tag":"TypeVar","contents":"o"}]}]}]}]},null]},null]},null]}
289 """
289 """
test/Test/TypeQuery.purs+383−229
@@ -15,384 +15,535 @@ import Data.List.NonEmpty as NonEmptyList
15import Data.Set as Set
15import Data.Set as Set
16import Data.Tuple (Tuple(..))
16import Data.Tuple (Tuple(..))
17import Test.Extra (assertRight)
17import Test.Extra (assertRight)
18−import Test.Unit (TestSuite, suite, test)
18+import Test.Spec (Spec, describe, it)
19−import Test.Unit.Assert as Assert
19+import Test.Spec.Assertions (shouldEqual, shouldSatisfy)
20import Data.Maybe (Maybe(..))
20import Data.Maybe (Maybe(..))
21
21
22−
22+tests :: Spec Unit
23−tests :: TestSuite
24tests = do
23tests = do
25− suite "TypeQuery parser" do
24+ describe "TypeQuery parser" do
26
25
27− test "test #0" do
26+ it "test #0" do
28 let input = "a"
27 let input = "a"
29 assertRight (parseTypeQuery input) (qVar "a")
28 assertRight (parseTypeQuery input) (qVar "a")
30
29
31− test "test #1" do
30+ it "test #1" do
32 let input = "ab"
31 let input = "ab"
33 assertRight (parseTypeQuery input) (qVar "ab")
32 assertRight (parseTypeQuery input) (qVar "ab")
34
33
35− test "test #2" do
34+ it "test #2" do
36 let input = "a b"
35 let input = "a b"
37 assertRight (parseTypeQuery input) (QApp (qVar "a") (qVar "b"))
36 assertRight (parseTypeQuery input) (QApp (qVar "a") (qVar "b"))
38
37
39− test "test #3" do
38+ it "test #3" do
40 let input = "a b c"
39 let input = "a b c"
41 assertRight (parseTypeQuery input) (QApp (QApp (qVar "a") (qVar "b")) (qVar "c"))
40 assertRight (parseTypeQuery input) (QApp (QApp (qVar "a") (qVar "b")) (qVar "c"))
42
41
43− test "test #4" do
42+ it "test #4" do
44 let input = "a -> b"
43 let input = "a -> b"
45 assertRight (parseTypeQuery input) (QFun (qVar "a") (qVar "b"))
44 assertRight (parseTypeQuery input) (QFun (qVar "a") (qVar "b"))
46
45
47− test "test #5" do
46+ it "test #5" do
48 let input = "a -> b c"
47 let input = "a -> b c"
49 assertRight (parseTypeQuery input) (QFun (qVar "a") (QApp (qVar "b") (qVar "c")))
48 assertRight (parseTypeQuery input) (QFun (qVar "a") (QApp (qVar "b") (qVar "c")))
50
49
51− test "test #6" do
50+ it "test #6" do
52 let input = "a b -> c"
51 let input = "a b -> c"
53 assertRight (parseTypeQuery input) (QFun (QApp (qVar "a") (qVar "b")) (qVar "c"))
52 assertRight (parseTypeQuery input) (QFun (QApp (qVar "a") (qVar "b")) (qVar "c"))
54
53
55− test "test #7" do
54+ it "test #7" do
56 let input = "a b"
55 let input = "a b"
57 assertRight (parseTypeQuery input) (QApp (qVar "a") (qVar "b"))
56 assertRight (parseTypeQuery input) (QApp (qVar "a") (qVar "b"))
58
57
59− test "test #8" do
58+ it "test #8" do
60 let input = "a (b c)"
59 let input = "a (b c)"
61 assertRight (parseTypeQuery input) (QApp (qVar "a") (QApp (qVar "b") (qVar "c")))
60 assertRight (parseTypeQuery input) (QApp (qVar "a") (QApp (qVar "b") (qVar "c")))
62
61
63− test "test #9" do
62+ it "test #9" do
64 let input = "(a b) (c d)"
63 let input = "(a b) (c d)"
65 assertRight (parseTypeQuery input)
64 assertRight (parseTypeQuery input)
66− (QApp (QApp (qVar "a") (qVar "b"))
65+ ( QApp (QApp (qVar "a") (qVar "b"))
67− (QApp (qVar "c") (qVar "d")))
66+ (QApp (qVar "c") (qVar "d"))
67+ )
68
68
69− test "test #10" do
69+ it "test #10" do
70 let input = "a ( b c )"
70 let input = "a ( b c )"
71 assertRight (parseTypeQuery input) (QApp (qVar "a") (QApp (qVar "b") (qVar "c")))
71 assertRight (parseTypeQuery input) (QApp (qVar "a") (QApp (qVar "b") (qVar "c")))
72
72
73− test "test #11" do
73+ it "test #11" do
74 let input = "aaa"
74 let input = "aaa"
75 assertRight (parseTypeQuery input) (qVar "aaa")
75 assertRight (parseTypeQuery input) (qVar "aaa")
76
76
77− test "test #12" do
77+ it "test #12" do
78 let input = "aaa ( bbb ccc )"
78 let input = "aaa ( bbb ccc )"
79 assertRight (parseTypeQuery input) (QApp (qVar "aaa") (QApp (qVar "bbb") (qVar "ccc")))
79 assertRight (parseTypeQuery input) (QApp (qVar "aaa") (QApp (qVar "bbb") (qVar "ccc")))
80
80
81− test "test #13" do
81+ it "test #13" do
82 let input = "(a -> b) -> (c -> d)"
82 let input = "(a -> b) -> (c -> d)"
83− assertRight (parseTypeQuery input) (QFun (QFun (qVar "a") (qVar "b"))
83+ assertRight (parseTypeQuery input)
84+ ( QFun (QFun (qVar "a") (qVar "b"))
84− (QFun (qVar "c") (qVar "d")))
85+ (QFun (qVar "c") (qVar "d"))
86+ )
85
87
86− test "test #14" do
88+ it "test #14" do
87 let input = "a -> b -> c -> d"
89 let input = "a -> b -> c -> d"
88− assertRight (parseTypeQuery input) (QFun (qVar "a")
90+ assertRight (parseTypeQuery input)
91+ ( QFun (qVar "a")
89− (QFun (qVar "b")
92+ ( QFun (qVar "b")
90− (QFun (qVar "c") (qVar "d"))))
93+ (QFun (qVar "c") (qVar "d"))
94+ )
95+ )
91
96
92− test "test #15" do
97+ it "test #15" do
93 let input = "a -> b -> c"
98 let input = "a -> b -> c"
94− assertRight (parseTypeQuery input) (QFun (qVar "a")
99+ assertRight (parseTypeQuery input)
100+ ( QFun (qVar "a")
95− (QFun (qVar "b")
101+ ( QFun (qVar "b")
96− (qVar "c")))
102+ (qVar "c")
103+ )
104+ )
97
105
98− test "test #16" do
106+ it "test #16" do
99 let input = "forall a b c. c"
107 let input = "forall a b c. c"
100− assertRight (parseTypeQuery input) (QForAll (nl "a" ["b", "c"]) (qVar "c"))
108+ assertRight (parseTypeQuery input) (QForAll (nl "a" [ "b", "c" ]) (qVar "c"))
101
109
102− test "test #17" do
110+ it "test #17" do
103 let input = "forall a. Maybe a"
111 let input = "forall a. Maybe a"
104 assertRight (parseTypeQuery input) (QForAll (nl "a" $ []) (QApp (qConst "Maybe") (qVar "a")))
112 assertRight (parseTypeQuery input) (QForAll (nl "a" $ []) (QApp (qConst "Maybe") (qVar "a")))
105
113
106− test "test #18" do
114+ it "test #18" do
107 let input = "forall m a. Monad m => a -> m a"
115 let input = "forall m a. Monad m => a -> m a"
108 assertRight (parseTypeQuery input)
116 assertRight (parseTypeQuery input)
109− (QForAll (nl "m" ["a"])
117+ ( QForAll (nl "m" [ "a" ])
110− (qConstraint "Monad" (l [qVar "m"])
118+ ( qConstraint "Monad" (l [ qVar "m" ])
111− (QFun (qVar "a")
119+ ( QFun (qVar "a")
112− (QApp (qVar "m") (qVar "a")))))
120+ (QApp (qVar "m") (qVar "a"))
113−
121+ )
122+ )
123+ )
124+
114− test "test #19" do
125+ it "test #19" do
115 let input = "{ a :: Int }"
126 let input = "{ a :: Int }"
116 assertRight (parseTypeQuery input)
127 assertRight (parseTypeQuery input)
117 (QApp (qConst "Record") (QRow (pure (Tuple (Identifier "a") (qConst "Int")))))
128 (QApp (qConst "Record") (QRow (pure (Tuple (Identifier "a") (qConst "Int")))))
118
129
119− test "test #20" do
130+ it "test #20" do
120 let input = "{a::Int}"
131 let input = "{a::Int}"
121 assertRight (parseTypeQuery input)
132 assertRight (parseTypeQuery input)
122 (QApp (qConst "Record") (QRow (pure (Tuple (Identifier "a") (qConst "Int")))))
133 (QApp (qConst "Record") (QRow (pure (Tuple (Identifier "a") (qConst "Int")))))
123
134
124− test "test #21" do
135+ it "test #21" do
125 let input = "Int"
136 let input = "Int"
126 assertRight (parseTypeQuery input) (qConst "Int")
137 assertRight (parseTypeQuery input) (qConst "Int")
127
138
128− test "test #22" do
139+ it "test #22" do
129 let input = "a->b"
140 let input = "a->b"
130 assertRight (parseTypeQuery input) (QFun (qVar "a") (qVar "b"))
141 assertRight (parseTypeQuery input) (QFun (qVar "a") (qVar "b"))
131
142
132− test "test #23" do
143+ it "test #23" do
133 let input = "forall m a. MonadRec m => Process m a -> m a"
144 let input = "forall m a. MonadRec m => Process m a -> m a"
134− assertRight (parseTypeQuery input) (QForAll (nl "m" ("a" : Nil))
145+ assertRight (parseTypeQuery input)
146+ ( QForAll (nl "m" ("a" : Nil))
135− (qConstraint "MonadRec" (l [qVar "m"])
147+ ( qConstraint "MonadRec" (l [ qVar "m" ])
148+ ( QFun
149+ ( QApp
136− (QFun (QApp (QApp (qConst "Process")
150+ ( QApp (qConst "Process")
137− (qVar "m")) (qVar "a"))
151+ (qVar "m")
152+ )
153+ (qVar "a")
154+ )
138− (QApp (qVar "m") (qVar "a")))))
155+ (QApp (qVar "m") (qVar "a"))
139−
156+ )
157+ )
158+ )
159+
140− test "test #24" do
160+ it "test #24" do
141 let input = "forall t f a. Foldable1 t => Apply f => f"
161 let input = "forall t f a. Foldable1 t => Apply f => f"
142− assertRight (parseTypeQuery input) (QForAll (nl "t" ["f", "a"])
162+ assertRight (parseTypeQuery input)
163+ ( QForAll (nl "t" [ "f", "a" ])
143− (qConstraint "Foldable1" (l [qVar "t"])
164+ ( qConstraint "Foldable1" (l [ qVar "t" ])
144− (qConstraint "Apply" (l [qVar "f"]) (qVar "f"))))
165+ (qConstraint "Apply" (l [ qVar "f" ]) (qVar "f"))
166+ )
167+ )
145
168
146− test "test #25" do
169+ it "test #25" do
147 let input = "forall m a.MonadRec m=>Process m a->m a"
170 let input = "forall m a.MonadRec m=>Process m a->m a"
148− assertRight (parseTypeQuery input) ((QForAll (nl "m" ("a" : Nil))
171+ assertRight (parseTypeQuery input)
172+ ( ( QForAll (nl "m" ("a" : Nil))
149− (qConstraint "MonadRec" (l [qVar "m"])
173+ ( qConstraint "MonadRec" (l [ qVar "m" ])
174+ ( QFun
175+ ( QApp
150− (QFun (QApp (QApp (qConst "Process")
176+ ( QApp (qConst "Process")
151− (qVar "m")) (qVar "a"))
177+ (qVar "m")
178+ )
179+ (qVar "a")
180+ )
152− (QApp (qVar "m") (qVar "a"))))))
181+ (QApp (qVar "m") (qVar "a"))
153−
182+ )
183+ )
184+ )
185+ )
186+
154− test "test #26" do
187+ it "test #26" do
155 let input = "m a -> (a -> m b) -> m b"
188 let input = "m a -> (a -> m b) -> m b"
156 assertRight (parseTypeQuery input) (QFun (QApp (qVar "m") (qVar "a")) (QFun (QFun (qVar "a") (QApp (qVar "m") (qVar "b"))) (QApp (qVar "m") (qVar "b"))))
189 assertRight (parseTypeQuery input) (QFun (QApp (qVar "m") (qVar "a")) (QFun (QFun (qVar "a") (QApp (qVar "m") (qVar "b"))) (QApp (qVar "m") (qVar "b"))))
157
190
158− test "test #27" do
191+ it "test #27" do
159 let input = "forall f a. Alternative f => Lazy (f (List a)) => f a -> f (List a)"
192 let input = "forall f a. Alternative f => Lazy (f (List a)) => f a -> f (List a)"
160− assertRight (parseTypeQuery input) ((QForAll (nl "f" ["a"]))
193+ assertRight (parseTypeQuery input)
194+ ( (QForAll (nl "f" [ "a" ]))
161− (qConstraint "Alternative" (l [qVar "f"])
195+ ( qConstraint "Alternative" (l [ qVar "f" ])
162− (qConstraint "Lazy" (l [QApp (qVar "f")
196+ ( qConstraint "Lazy"
197+ ( l
198+ [ QApp (qVar "f")
163− (QApp (qConst "List") (qVar "a"))])
199+ (QApp (qConst "List") (qVar "a"))
200+ ]
201+ )
164− (QFun (QApp (qVar "f") (qVar "a"))
202+ ( QFun (QApp (qVar "f") (qVar "a"))
165− (QApp (qVar "f")
203+ ( QApp (qVar "f")
166− (QApp (qConst "List") (qVar "a")))))))
204+ (QApp (qConst "List") (qVar "a"))
167−
205+ )
206+ )
207+ )
208+ )
209+ )
210+
168− test "test #28" do
211+ it "test #28" do
169 let input = "forall f a. Alternative f => Lazy(f (List a))=>f a -> f (List a)"
212 let input = "forall f a. Alternative f => Lazy(f (List a))=>f a -> f (List a)"
170− assertRight (parseTypeQuery input) ((QForAll (nl "f" ["a"]))
213+ assertRight (parseTypeQuery input)
214+ ( (QForAll (nl "f" [ "a" ]))
171− (qConstraint "Alternative" (l [qVar "f"])
215+ ( qConstraint "Alternative" (l [ qVar "f" ])
172− (qConstraint "Lazy" (l [QApp (qVar "f")
216+ ( qConstraint "Lazy"
217+ ( l
218+ [ QApp (qVar "f")
173− (QApp (qConst "List") (qVar "a"))])
219+ (QApp (qConst "List") (qVar "a"))
220+ ]
221+ )
174− (QFun (QApp (qVar "f") (qVar "a"))
222+ ( QFun (QApp (qVar "f") (qVar "a"))
175− (QApp (qVar "f")
223+ ( QApp (qVar "f")
176− (QApp (qConst "List") (qVar "a")))))))
224+ (QApp (qConst "List") (qVar "a"))
177−
225+ )
226+ )
227+ )
228+ )
229+ )
230+
178− test "test #29" do
231+ it "test #29" do
179 let input = "{a::Int,b::Int}"
232 let input = "{a::Int,b::Int}"
180 assertRight (parseTypeQuery input)
233 assertRight (parseTypeQuery input)
181− (QApp (qConst "Record") (QRow (List.fromFoldable
234+ ( QApp (qConst "Record")
235+ ( QRow
236+ ( List.fromFoldable
182− [ Tuple (Identifier "a") (qConst "Int")
237+ [ Tuple (Identifier "a") (qConst "Int")
183− , Tuple (Identifier "b") (qConst "Int")])))
238+ , Tuple (Identifier "b") (qConst "Int")
184−
239+ ]
240+ )
241+ )
242+ )
243+
185− test "test #30" do
244+ it "test #30" do
186 let input = "{record''' :: Int}"
245 let input = "{record''' :: Int}"
187 assertRight (parseTypeQuery input)
246 assertRight (parseTypeQuery input)
188− (QApp (qConst "Record") (QRow (List.fromFoldable [ Tuple (Identifier "record'''") (qConst "Int")])))
247+ (QApp (qConst "Record") (QRow (List.fromFoldable [ Tuple (Identifier "record'''") (qConst "Int") ])))
189
248
190− test "test #31" do
249+ it "test #31" do
191 let input = "(row''' :: Int)"
250 let input = "(row''' :: Int)"
192 assertRight (parseTypeQuery input)
251 assertRight (parseTypeQuery input)
193− (QRow (List.fromFoldable [ Tuple (Identifier "row'''") (qConst "Int")]))
252+ (QRow (List.fromFoldable [ Tuple (Identifier "row'''") (qConst "Int") ]))
194
253
195− test "test #32" do
254+ it "test #32" do
196 let input = "(row1 :: Int, row2 :: (),row3::(row4::{}))"
255 let input = "(row1 :: Int, row2 :: (),row3::(row4::{}))"
197 assertRight (parseTypeQuery input)
256 assertRight (parseTypeQuery input)
257+ ( QRow
258+ ( l
198− (QRow (l [ Tuple (Identifier "row1") (qConst "Int")
259+ [ Tuple (Identifier "row1") (qConst "Int")
199− , Tuple (Identifier "row2") (QRow Nil)
260+ , Tuple (Identifier "row2") (QRow Nil)
200− , Tuple (Identifier "row3") (QRow (l [ Tuple (Identifier "row4") (QApp (qConst "Record") (QRow Nil)) ])) ]))
261+ , Tuple (Identifier "row3") (QRow (l [ Tuple (Identifier "row4") (QApp (qConst "Record") (QRow Nil)) ]))
201−
262+ ]
263+ )
264+ )
265+
202− test "test #33" do
266+ it "test #33" do
203 let input = "Foldable1 t => Apply f => t (f a) -> f Unit"
267 let input = "Foldable1 t => Apply f => t (f a) -> f Unit"
204 assertRight (parseTypeQuery input)
268 assertRight (parseTypeQuery input)
205 (qConstraint "Foldable1" ((qVar "t") : Nil) (qConstraint "Apply" ((qVar "f") : Nil) (QFun (QApp (qVar "t") (QApp (qVar "f") (qVar "a"))) (QApp (qVar "f") (qConst "Unit")))))
269 (qConstraint "Foldable1" ((qVar "t") : Nil) (qConstraint "Apply" ((qVar "f") : Nil) (QFun (QApp (qVar "t") (QApp (qVar "f") (qVar "a"))) (QApp (qVar "f") (qConst "Unit")))))
206
270
207− test "test #34" do
271+ it "test #34" do
208 let input = "Foldable1 t => Apply f => t (f a) -> f a"
272 let input = "Foldable1 t => Apply f => t (f a) -> f a"
209 assertRight (parseTypeQuery input)
273 assertRight (parseTypeQuery input)
210 (qConstraint "Foldable1" ((qVar "t") : Nil) (qConstraint "Apply" ((qVar "f") : Nil) (QFun (QApp (qVar "t") (QApp (qVar "f") (qVar "a"))) (QApp (qVar "f") (qVar "a")))))
274 (qConstraint "Foldable1" ((qVar "t") : Nil) (qConstraint "Apply" ((qVar "f") : Nil) (QFun (QApp (qVar "t") (QApp (qVar "f") (qVar "a"))) (QApp (qVar "f") (qVar "a")))))
211
275
212− test "test #35" do
276+ it "test #35" do
213 let input = "Generic a rep => GenericEq rep => a -> a -> Boolean"
277 let input = "Generic a rep => GenericEq rep => a -> a -> Boolean"
214 assertRight (parseTypeQuery input)
278 assertRight (parseTypeQuery input)
215− (qConstraint "Generic" ((qVar "a") : (qVar "rep") : Nil)
279+ ( qConstraint "Generic" ((qVar "a") : (qVar "rep") : Nil)
216− (qConstraint "GenericEq" ((qVar "rep") : Nil)
280+ ( qConstraint "GenericEq" ((qVar "rep") : Nil)
217− (QFun (qVar "a") (QFun (qVar "a") (qConst "Boolean")))))
281+ (QFun (qVar "a") (QFun (qVar "a") (qConst "Boolean")))
282+ )
283+ )
218
284
219− suite "polish notation" do
285+ describe "polish notation" do
220
286
221− test "test #1" do
287+ it "test #1" do
222 let input = "(a -> b) -> (b -> ((a -> b) -> c))"
288 let input = "(a -> b) -> (b -> ((a -> b) -> c))"
223 assertRight (shapeOfTypeQuery <$> parseTypeQuery input)
289 assertRight (shapeOfTypeQuery <$> parseTypeQuery input)
224− (l [ PForAll 3, PFun, PFun, PVar, PVar, PFun, PVar, PFun, PFun
290+ ( l
291+ [ PForAll 3
292+ , PFun
293+ , PFun
294+ , PVar
295+ , PVar
296+ , PFun
297+ , PVar
298+ , PFun
299+ , PFun
225− , PVar, PVar, PVar ])
300+ , PVar
226−
301+ , PVar
302+ , PVar
303+ ]
304+ )
305+
227− test "test #2" do
306+ it "test #2" do
228 let input = "forall a. (a -> b) -> (b -> ((a -> b) -> c))"
307 let input = "forall a. (a -> b) -> (b -> ((a -> b) -> c))"
229 assertRight (shapeOfTypeQuery <$> parseTypeQuery input)
308 assertRight (shapeOfTypeQuery <$> parseTypeQuery input)
230− (l [ PForAll 3, PFun, PFun, PVar, PVar, PFun, PVar, PFun, PFun
309+ ( l
310+ [ PForAll 3
311+ , PFun
312+ , PFun
313+ , PVar
314+ , PVar
315+ , PFun
316+ , PVar
317+ , PFun
318+ , PFun
231− , PVar, PVar, PVar ])
319+ , PVar
232−
320+ , PVar
321+ , PVar
322+ ]
323+ )
324+
233− test "test #3" do
325+ it "test #3" do
234 let input = "forall a. (a -> b) -> (b -> ((a -> b) -> c))"
326 let input = "forall a. (a -> b) -> (b -> ((a -> b) -> c))"
235 assertRight (shapeOfTypeQuery <$> parseTypeQuery input)
327 assertRight (shapeOfTypeQuery <$> parseTypeQuery input)
236− (l [ PForAll 3, PFun, PFun, PVar, PVar, PFun, PVar, PFun, PFun
328+ ( l
329+ [ PForAll 3
330+ , PFun
331+ , PFun
332+ , PVar
333+ , PVar
334+ , PFun
335+ , PVar
336+ , PFun
337+ , PFun
237− , PVar, PVar, PVar ])
338+ , PVar
238−
339+ , PVar
340+ , PVar
341+ ]
342+ )
343+
239− test "test #4" do
344+ it "test #4" do
240 let input = "forall a. (forall h. ST h (STArray h a)) -> Array a"
345 let input = "forall a. (forall h. ST h (STArray h a)) -> Array a"
241 assertRight (shapeOfTypeQuery <$> parseTypeQuery input)
346 assertRight (shapeOfTypeQuery <$> parseTypeQuery input)
242− (l [ PForAll 1, PFun, PForAll 1, PApp, PApp, PVar, PVar, PApp, PApp, PVar, PVar, PVar, PApp, PVar, PVar ])
347+ (l [ PForAll 1, PFun, PForAll 1, PApp, PApp, PVar, PVar, PApp, PApp, PVar, PVar, PVar, PApp, PVar, PVar ])
243−
348+
244− suite "type shapes" do
349+ describe "type shapes" do
245− test "test #1" do
350+ it "test #1" do
351+ let
246− let query = "Generic a rep => GenericEq rep => a -> a -> Boolean"
352+ query = "Generic a rep => GenericEq rep => a -> a -> Boolean"
247− c1 = constr (qname [""] "Generic") [TypeVar "a", TypeVar "rep"]
353+ c1 = constr (qname [ "" ] "Generic") [ TypeVar "a", TypeVar "rep" ]
248− c2 = constr (qname [""] "GenericEq") [TypeVar "rep"]
354+ c2 = constr (qname [ "" ] "GenericEq") [ TypeVar "rep" ]
249−
355+
250− fun t1 t2 =
356+ fun t1 t2 =
357+ TypeApp
358+ ( TypeApp
359+ ( TypeConstructor
360+ ( QualifiedName
251− TypeApp (TypeApp (TypeConstructor (QualifiedName { moduleNameParts: ["Prim"]
361+ { moduleNameParts: [ "Prim" ]
252− , name: Identifier "Function" })) t1) t2
362+ , name: Identifier "Function"
363+ }
364+ )
365+ )
366+ t1
367+ )
368+ t2
253− type_ =
369+ type_ =
254− ForAll "a" Nothing $
370+ ForAll "a" Nothing
255− ForAll "rep" Nothing $
371+ $ ForAll "rep" Nothing
372+ $
256− ConstrainedType c1
373+ ConstrainedType c1
257− (ConstrainedType c2
374+ ( ConstrainedType c2
258− (fun (TypeVar "a") (fun (TypeVar "b")
375+ ( fun (TypeVar "a")
376+ ( fun (TypeVar "b")
259− (TypeConstructor $ qname ["Prim", "Boolean"] "Boolean"))))
377+ (TypeConstructor $ qname [ "Prim", "Boolean" ] "Boolean")
378+ )
379+ )
380+ )
260− shape = shapeOfTypeQuery <$> parseTypeQuery query
381+ shape = shapeOfTypeQuery <$> parseTypeQuery query
261− Assert.equal (pure $ shapeOfType type_) shape
382+ pure (shapeOfType type_) `shouldEqual` shape
262−
383+
263− suite "free variable counting" do
384+ describe "free variable counting" do
264−
385+
265− test "test #1" do
386+ it "test #1" do
266 let input = "forall a. (a -> b) -> (b -> ((a -> b) -> c))"
387 let input = "forall a. (a -> b) -> (b -> ((a -> b) -> c))"
267 assertRight (countFreeVars <$> parseTypeQuery input) 2
388 assertRight (countFreeVars <$> parseTypeQuery input) 2
268
389
269− test "test #2" do
390+ it "test #2" do
270 -- `b` is not bound on the left, `a` is not bound on the right
391 -- `b` is not bound on the left, `a` is not bound on the right
271 let input = "(forall a. (a -> b)) -> forall b. (b -> a)"
392 let input = "(forall a. (a -> b)) -> forall b. (b -> a)"
272 assertRight (countFreeVars <$> parseTypeQuery input) 2
393 assertRight (countFreeVars <$> parseTypeQuery input) 2
273
394
274− test "test #3" do
395+ it "test #3" do
275 let input = "a -> forall a. a"
396 let input = "a -> forall a. a"
276 assertRight (countFreeVars <$> parseTypeQuery input) 1
397 assertRight (countFreeVars <$> parseTypeQuery input) 1
277
398
278− test "test #4" do
399+ it "test #4" do
279 let input = "(forall a. a) -> a"
400 let input = "(forall a. a) -> a"
280 assertRight (countFreeVars <$> parseTypeQuery input) 1
401 assertRight (countFreeVars <$> parseTypeQuery input) 1
281
402
282− test "test #5" do
403+ it "test #5" do
283 let input = "forall a. a -> a"
404 let input = "forall a. a -> a"
284 assertRight (countFreeVars <$> parseTypeQuery input) 0
405 assertRight (countFreeVars <$> parseTypeQuery input) 0
285
406
286− test "test #6" do
407+ it "test #6" do
287 let input = "a -> b -> c"
408 let input = "a -> b -> c"
288 assertRight (countFreeVars <$> parseTypeQuery input) 3
409 assertRight (countFreeVars <$> parseTypeQuery input) 3
289
410
290− test "test #7" do
411+ it "test #7" do
291 let input = "forall m a. Monad m => a -> m a"
412 let input = "forall m a. Monad m => a -> m a"
292 assertRight (countFreeVars <$> parseTypeQuery input) 0
413 assertRight (countFreeVars <$> parseTypeQuery input) 0
293
414
294− test "test #8" do
415+ it "test #8" do
295 let input = "Monad m => a -> m a"
416 let input = "Monad m => a -> m a"
296 assertRight (countFreeVars <$> parseTypeQuery input) 2
417 assertRight (countFreeVars <$> parseTypeQuery input) 2
297
418
298− test "test #9" do
419+ it "test #9" do
299 let input = "Monad m => a -> a"
420 let input = "Monad m => a -> a"
300 assertRight (countFreeVars <$> parseTypeQuery input) 2
421 assertRight (countFreeVars <$> parseTypeQuery input) 2
301
422
302− test "test #10" do
423+ it "test #10" do
303 let input = "forall a. (forall a. a) a"
424 let input = "forall a. (forall a. a) a"
304 assertRight (countFreeVars <$> parseTypeQuery input) 0
425 assertRight (countFreeVars <$> parseTypeQuery input) 0
305
426
306− test "test #11" do
427+ it "test #11" do
307 let input = "forall a. (forall b. a) a"
428 let input = "forall a. (forall b. a) a"
308 assertRight (countFreeVars <$> parseTypeQuery input) 0
429 assertRight (countFreeVars <$> parseTypeQuery input) 0
309
430
310− test "test #12" do
431+ it "test #12" do
311 let input = "forall a. (forall b. a) a b"
432 let input = "forall a. (forall b. a) a b"
312 assertRight (countFreeVars <$> parseTypeQuery input) 1
433 assertRight (countFreeVars <$> parseTypeQuery input) 1
313
434
314− suite "typeVarPenalty" do
435+ describe "typeVarPenalty" do
315−
436+
316− test "#0" do
437+ it "#0" do
317− Assert.equal 0 (typeVarPenalty mempty)
438+ 0 `shouldEqual` (typeVarPenalty mempty)
318−
439+
319− test "#1" do
440+ it "#1" do
441+ 0 `shouldEqual`
320− Assert.equal 0 (typeVarPenalty $ l [ substitute "a" "b"
442+ ( typeVarPenalty $ l
443+ [ substitute "a" "b"
321− , substitute "b" "a"
444+ , substitute "b" "a"
322− ])
445+ ]
323−
446+ )
447+
324− test "#2" do
448+ it "#2" do
449+ 0 `shouldEqual`
325− Assert.equal 0 (typeVarPenalty $ l [ substitute "a" "b"
450+ ( typeVarPenalty $ l
451+ [ substitute "a" "b"
326− , substitute "a" "b"
452+ , substitute "a" "b"
327− , substitute "a" "b"
453+ , substitute "a" "b"
328− ])
454+ ]
329−
455+ )
456+
330− test "#3" do
457+ it "#3" do
458+ 1 `shouldEqual`
331− Assert.equal 1 (typeVarPenalty $ l [ substitute "a" "b"
459+ ( typeVarPenalty $ l
460+ [ substitute "a" "b"
332− , substitute "a" "c"
461+ , substitute "a" "c"
333− ])
462+ ]
334−
463+ )
464+
335− test "#4" do
465+ it "#4" do
466+ 1 `shouldEqual`
336− Assert.equal 1 (typeVarPenalty $ l [ substitute "a" "b"
467+ ( typeVarPenalty $ l
468+ [ substitute "a" "b"
337− , substitute "b" "a"
469+ , substitute "b" "a"
338− , substitute "b" "c"
470+ , substitute "b" "c"
339− ])
471+ ]
340−
472+ )
473+
341− test "#5" do
474+ it "#5" do
475+ 0 `shouldEqual`
342− Assert.equal 0 (typeVarPenalty $ l [ substitute "a" "b"
476+ ( typeVarPenalty $ l
477+ [ substitute "a" "b"
343− , substitute "b" "c"
478+ , substitute "b" "c"
344− , substitute "c" "a"
479+ , substitute "c" "a"
345− ])
480+ ]
346−
481+ )
482+
347− test "#6" do
483+ it "#6" do
484+ 2 `shouldEqual`
348− Assert.equal 2 (typeVarPenalty $ l [ substitute "a" "b"
485+ ( typeVarPenalty $ l
486+ [ substitute "a" "b"
349− , substitute "a" "c"
487+ , substitute "a" "c"
350− , substitute "a" "a"
488+ , substitute "a" "a"
351− ])
489+ ]
352−
490+ )
491+
353− test "#7" do
492+ it "#7" do
493+ 2 `shouldEqual`
354− Assert.equal 2 (typeVarPenalty $ l [ substitute "a" "a"
494+ ( typeVarPenalty $ l
495+ [ substitute "a" "a"
355− , substitute "b" "a"
496+ , substitute "b" "a"
356− , substitute "c" "a"
497+ , substitute "c" "a"
357− ])
498+ ]
358−
499+ )
500+
359− test "#8" do
501+ it "#8" do
502+ 4 `shouldEqual`
360− Assert.equal 4 (typeVarPenalty $ l [ substitute "a" "a"
503+ ( typeVarPenalty $ l
504+ [ substitute "a" "a"
361− , substitute "b" "a"
505+ , substitute "b" "a"
362− , substitute "c" "a"
506+ , substitute "c" "a"
363− , substitute "a" "b"
507+ , substitute "a" "b"
364− , substitute "a" "c"
508+ , substitute "a" "c"
365− , substitute "a" "a"
509+ , substitute "a" "a"
366− ])
510+ ]
367−
511+ )
512+
368− test "#9" do
513+ it "#9" do
514+ 0 `shouldEqual`
369− Assert.equal 0 (typeVarPenalty $ l [ substitute "a" "e"
515+ ( typeVarPenalty $ l
516+ [ substitute "a" "e"
370− , substitute "b" "d"
517+ , substitute "b" "d"
371− , substitute "c" "f"
518+ , substitute "c" "f"
372− ])
519+ ]
373−
520+ )
521+
374− suite "unification" do
522+ describe "unification" do
375− test "instantiation #0" do
523+ it "instantiation #0" do
524+ let
376− let mVarQuery = qVar "m"
525+ mVarQuery = qVar "m"
377− unitConstQuery = qConst "Unit"
526+ unitConstQuery = qConst "Unit"
378−
527+
379− Assert.assert "instantiation #0" $
528+ shouldSatisfy
380− (penalty unitConstQuery unitType < penalty mVarQuery unitType)
529+ (penalty unitConstQuery unitType)
381−
530+ (_ < penalty mVarQuery unitType)
531+
382− test "generalization #0" do
532+ it "generalization #0" do
533+ let
383− let query = qVar "m"
534+ query = qVar "m"
384− t1 = TypeVar "m"
535+ t1 = TypeVar "m"
385−
536+
386− Assert.assert "qeneralization #0" $
537+ shouldSatisfy
387− (penalty query unitType > penalty query t1)
538+ (penalty query unitType)
388−
539+ (_ > penalty query t1)
389
540
390l :: forall f. Foldable f => (forall a. f a -> List a)
541l :: forall f. Foldable f => (forall a. f a -> List a)
391l = List.fromFoldable
542l = List.fromFoldable
392
543
393nl
544nl
394 :: forall t
545 :: forall t
395− . Foldable t
546+ . Foldable t
396 => Functor t
547 => Functor t
397 => String
548 => String
398 -> t String
549 -> t String
@@ -400,9 +551,12 @@ nl
400nl x rst = NonEmptyList.cons' (Identifier x) $ List.fromFoldable (rst <#> Identifier)
551nl x rst = NonEmptyList.cons' (Identifier x) $ List.fromFoldable (rst <#> Identifier)
401
552
402unitType :: Type
553unitType :: Type
403−unitType = TypeConstructor (QualifiedName { moduleNameParts: []
554+unitType = TypeConstructor
555+ ( QualifiedName
556+ { moduleNameParts: []
404− , name: Identifier "Unit"
557+ , name: Identifier "Unit"
405− })
558+ }
559+ )
406
560
407countFreeVars :: TypeQuery -> Int
561countFreeVars :: TypeQuery -> Int
408countFreeVars = getFreeVariables >>> Set.size
562countFreeVars = getFreeVariables >>> Set.size