diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-05-09 18:06:18 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:23:21 +0000 |
| commit | 27e57ad5b46e7edae454dbb74b70013fefe00eb9 (patch) | |
| tree | 51ed20e54c86e30ecd4f7a4a8707a48183b98d5e | |
| parent | exclude Constants from side_inputs (diff) | |
| download | alive-27e57ad5b46e7edae454dbb74b70013fefe00eb9.tar.gz alive-27e57ad5b46e7edae454dbb74b70013fefe00eb9.zip | |
make tostring Scope deterministic and test it
| -rw-r--r-- | alv/scope.moon | 5 | ||||
| -rw-r--r-- | spec/scope_spec.moon | 17 |
2 files changed, 20 insertions, 2 deletions
diff --git a/alv/scope.moon b/alv/scope.moon index 4adf07d..7f4b14f 100644 --- a/alv/scope.moon +++ b/alv/scope.moon @@ -6,6 +6,7 @@ import Constant from require 'alv.result' import RTNode from require 'alv.rtnode' import Error from require 'alv.error' import T from require 'alv.type' +import opairs from require 'alv.util' class Scope --- members @@ -81,10 +82,10 @@ class Scope parent = parent.parent buf ..= " ^#{depth}" if depth != 0 - keys = [key for key in pairs @values] + keys = [key for key in opairs @values] if #keys > 5 keys = [key for key in *keys[,5]] - keys[6] = '...' + keys[6] = '…' buf ..= " [#{table.concat keys, ', '}]" buf ..= ">" diff --git a/spec/scope_spec.moon b/spec/scope_spec.moon index 637b5f5..b4a55f1 100644 --- a/spec/scope_spec.moon +++ b/spec/scope_spec.moon @@ -52,6 +52,23 @@ describe 'Scope', -> assert.is.equal pi, (got.value\get 'pi')\const! assert.is.equal pi, (scope\get 'math/pi')\const! + it 'stringifies well', -> + scope = Scope.from_table { + num: 3 + str: "im a happy string" + :pi + math: :pi + test: TestOp + } + sub = Scope Scope scope + + assert.is.equal "<Scope ^1 []>", tostring sub + assert.is.equal "<Scope ^-1 [math, num, str, test]>", tostring scope + scope\set_raw 'a', Constant.num 1 + scope\set_raw 'b', Constant.num 2 + scope\set_raw 'c', Constant.num 3 + assert.is.equal "<Scope ^-1 [a, b, c, math, num, …]>", tostring scope + it 'wraps Values in from_table', -> pi = Constant.num 3.14 scope = Scope.from_table { |
