diff options
| -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 { |
