Fix name comparison to take into account absolute names

Transcripts all pass, but have a lot of diffs that I need to investigate
This commit is contained in:
Paul Chiusano 2021-08-01 17:49:24 -04:00
parent d10adcf0fb
commit 41b8068b43
3 changed files with 17 additions and 6 deletions

View File

@ -201,8 +201,12 @@ countSegments n = length (segments n)
-- `sortNamed` or one of its variants should be used, which provides a
-- Unicode and capitalization aware sorting (based on RFC5051).
instance Ord Name where
compare (Name n1) (Name n2) =
NameSegment.reverseSegments' n1 `compare` NameSegment.reverseSegments' n2
compare n1 n2 =
(reverseSegments n1 `compare` reverseSegments n2)
<> (isAbsolute n1 `compare` isAbsolute n2)
isAbsolute :: Name -> Bool
isAbsolute (Name n) = Text.isPrefixOf "." n
-- Find all `r` in the given `Relation` whose corresponding name has the
-- provided suffix, using logarithmic time lookups.

View File

@ -1,5 +1,12 @@
# Unit tests for builtin functions
```ucm:hide
.> builtins.mergeio
.> cd builtin
.> load unison-src/transcripts-using-base/base.u
.> add
```
This transcript defines unit tests for builtin functions. There's a single `.> test` execution at the end that will fail the transcript with a nice report if any of the tests fail.
## `Int` functions
@ -69,7 +76,7 @@ test> Int.tests.conversions =
toText +10 == "10",
toText -1039 == "-1039",
fromText "+0" == Some +0,
fromText "a8f9djasdlfkj" == None,
Int.fromText "a8f9djasdlfkj" == None,
fromText "3940" == Some +3940,
toFloat +9394 == 9394.0,
toFloat -20349 == -20349.0
@ -138,7 +145,7 @@ test> Nat.tests.conversions =
toText 0 == "0",
toText 32939 == "32939",
toText 10 == "10",
fromText "ooga" == None,
Nat.fromText "ooga" == None,
fromText "90" == Some 90,
unsnoc "abc" == Some ("ab", ?c),
uncons "abc" == Some (?a, "bc"),

View File

@ -69,7 +69,7 @@ test> Int.tests.conversions =
toText +10 == "10",
toText -1039 == "-1039",
fromText "+0" == Some +0,
fromText "a8f9djasdlfkj" == None,
Int.fromText "a8f9djasdlfkj" == None,
fromText "3940" == Some +3940,
toFloat +9394 == 9394.0,
toFloat -20349 == -20349.0
@ -134,7 +134,7 @@ test> Nat.tests.conversions =
toText 0 == "0",
toText 32939 == "32939",
toText 10 == "10",
fromText "ooga" == None,
Nat.fromText "ooga" == None,
fromText "90" == Some 90,
unsnoc "abc" == Some ("ab", ?c),
uncons "abc" == Some (?a, "bc"),