From 578d1ee751fa8165a64c842c40216a752caf47e2 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 24 Feb 2021 14:17:16 -0800 Subject: [PATCH] `std/options`: `$some(3)` is now `"some(3)"`, etc. (#17147) * std/options: $some(3) is now "some(3)", not "Some(3)", `$none(int)` is now `"none(int)"` instead of `"None[int]"` * fix tests * disable optionsutils --- changelog.md | 3 +++ lib/pure/options.nim | 24 +++++++++++++++--------- testament/important_packages.nim | 2 +- tests/generics/tgenerics_issues.nim | 6 +++--- tests/stdlib/tmarshal.nim | 4 ++-- tests/stdlib/toptions.nim | 10 +++++----- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/changelog.md b/changelog.md index 6fe730ffbd..6b2c412f06 100644 --- a/changelog.md +++ b/changelog.md @@ -178,6 +178,9 @@ provided by the operating system. - Added to `wrapnils` an option-like API via `??.`, `isSome`, `get`. +- `std/options` changed `$some(3)` to `"some(3)"` instead of `"Some(3)"` + and `$none(int)` to `"none(int)"` instead of `"None[int]"`. + ## Language changes - `nimscript` now handles `except Exception as e`. diff --git a/lib/pure/options.nim b/lib/pure/options.nim index 69feee7dc5..63e3598f09 100644 --- a/lib/pure/options.nim +++ b/lib/pure/options.nim @@ -306,8 +306,8 @@ proc flatMap*[T, R](self: Option[T], proc filter*[T](self: Option[T], callback: proc (input: T): bool): Option[T] {.inline.} = ## Applies a `callback` to the value of the `Option`. ## - ## If the `callback` returns `true`, the option is returned as `Some`. - ## If it returns `false`, it is returned as `None`. + ## If the `callback` returns `true`, the option is returned as `some`. + ## If it returns `false`, it is returned as `none`. ## ## **See also:** ## * `flatMap proc <#flatMap,Option[A],proc(A)>`_ @@ -325,8 +325,8 @@ proc filter*[T](self: Option[T], callback: proc (input: T): bool): Option[T] {.i self proc `==`*[T](a, b: Option[T]): bool {.inline.} = - ## Returns `true` if both `Option`s are `None`, - ## or if they are both `Some` and have equal values. + ## Returns `true` if both `Option`s are `none`, + ## or if they are both `some` and have equal values. runnableExamples: let a = some(42) @@ -346,18 +346,24 @@ proc `==`*[T](a, b: Option[T]): bool {.inline.} = proc `$`*[T](self: Option[T]): string = ## Get the string representation of the `Option`. runnableExamples: - assert $some(42) == "Some(42)" - assert $none(int) == "None[int]" + assert $some(42) == "some(42)" + assert $none(int) == "none(int)" if self.isSome: - result = "Some(" + when defined(nimLagacyOptionsDollar): + result = "Some(" + else: + result = "some(" result.addQuoted self.val result.add ")" else: - result = "None[" & name(T) & "]" + when defined(nimLagacyOptionsDollar): + result = "None[" & name(T) & "]" + else: + result = "none(" & name(T) & ")" proc unsafeGet*[T](self: Option[T]): lent T {.inline.}= - ## Returns the value of a `Some`. The behavior is undefined for `None`. + ## Returns the value of a `some`. The behavior is undefined for `none`. ## ## **Note:** Use this only when you are **absolutely sure** the value is present ## (e.g. after checking with `isSome <#isSome,Option[T]>`_). diff --git a/testament/important_packages.nim b/testament/important_packages.nim index b913f46267..ccf8a4359e 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -114,7 +114,7 @@ pkg2 "nimwc", "nim c nimwc.nim" pkg2 "norm", "nim c -r tests/sqlite/trows.nim" pkg2 "npeg", "nimble testarc" pkg2 "numericalnim", "nim c -r tests/test_integrate.nim" -pkg2 "optionsutils" +# pkg2 "optionsutils" # pending changing test from `Some` to `some` (etc) in tests/test2.nim, refs #17147 pkg2 "ormin", "nim c -o:orminn ormin.nim" pkg2 "parsetoml" pkg2 "patty" diff --git a/tests/generics/tgenerics_issues.nim b/tests/generics/tgenerics_issues.nim index 46b4c21c92..9e70efcd29 100644 --- a/tests/generics/tgenerics_issues.nim +++ b/tests/generics/tgenerics_issues.nim @@ -24,9 +24,9 @@ G:0,1:0.1 G:0,1:0.1 H:1:0.1 0 -(foo: None[seq[Foo]], s: "") -(foo: Some(@[(a: "world", bar: None[Bar])]), s: "hello,") -@[(a: "hey", bar: None[Bar])] +(foo: none(seq[Foo]), s: "") +(foo: some(@[(a: "world", bar: none(Bar))]), s: "hello,") +@[(a: "hey", bar: none(Bar))] ''' joinable: false """ diff --git a/tests/stdlib/tmarshal.nim b/tests/stdlib/tmarshal.nim index 7d4dee4f06..508205c3ae 100644 --- a/tests/stdlib/tmarshal.nim +++ b/tests/stdlib/tmarshal.nim @@ -116,8 +116,8 @@ block: let a1 = some(newJNull()) a2 = none(JsonNode) - doAssert $($$a1).to[:Option[JsonNode]] == "Some(null)" - doAssert $($$a2).to[:Option[JsonNode]] == "None[JsonNode]" + doAssert $($$a1).to[:Option[JsonNode]] == "some(null)" + doAssert $($$a2).to[:Option[JsonNode]] == "none(JsonNode)" doAssert ($$a1).to[:Option[JsonNode]] == some(newJNull()) doAssert ($$a2).to[:Option[JsonNode]] == none(JsonNode) diff --git a/tests/stdlib/toptions.nim b/tests/stdlib/toptions.nim index 4764ce05fc..71c52a07e4 100644 --- a/tests/stdlib/toptions.nim +++ b/tests/stdlib/toptions.nim @@ -82,8 +82,8 @@ proc main() = doAssert(stringNone.get("Correct") == "Correct") block stringify: - doAssert($(some("Correct")) == "Some(\"Correct\")") - doAssert($(stringNone) == "None[string]") + doAssert($(some("Correct")) == "some(\"Correct\")") + doAssert($(stringNone) == "none(string)") disableJsVm: block map_with_a_void_result: @@ -155,7 +155,7 @@ proc main() = name: string let nobody = none(Named) - doAssert($nobody == "None[Named]") + doAssert($nobody == "none(Named)") # "$ on type with name()" block: @@ -163,7 +163,7 @@ proc main() = myname: string let noperson = none(Person) - doAssert($noperson == "None[Person]") + doAssert($noperson == "none(Person)") # "Ref type with overloaded `==`" block: @@ -190,7 +190,7 @@ proc main() = block: let x = none(cstring) doAssert x.isNone - doAssert $x == "None[cstring]" + doAssert $x == "none(cstring)" static: main()