UNPKG

@mojir/lits

Version:

Lits is a pure functional programming language implemented in TypeScript

3 lines (2 loc) 29.4 kB
function e(e){if(!e.position||!e.code)return"";const t=e.position.column-1,s=e.code.length-t-1;return`${" ".repeat(Math.max(t,0))}^${" ".repeat(Math.max(s,0))}`}class t extends Error{sourceCodeInfo;shortMessage;constructor(s,r){const a=s instanceof Error?s.message:`${s}`;super(function(t,s){if(!s)return t;const r=`${s.position.line}:${s.position.column}`;return`${t}${s.filePath?`\n${s.filePath}:${r}`:`\nLocation ${r}`}\n${s.code}\n${e(s)}`}(a,r)),this.shortMessage=a,this.sourceCodeInfo=r,Object.setPrototypeOf(this,t.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}class s extends t{constructor(e,t){super(e,t),Object.setPrototypeOf(this,s.prototype),this.name="AssertionError"}}const r={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},a=new Set(Object.values(r));const n=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const o="^^fn^^";function i(e){return null!==e&&"object"==typeof e&&(o in e&&"functionType"in e&&("string"==typeof(t=e.functionType)&&n.has(t)));var t}function l(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(t=e[0])&&a.has(t));var t}function u(e){return i(e)?`<function ${e.name||"λ"}>`:l(e)?`${t=e[0],Object.keys(r).find(e=>r[e]===t)}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e);var t}function m(e,s,r){return new t(`Expected ${e}, got ${u(s)}.`,function(e,t){return e?.sourceCodeInfo??t}(s,r))}function c(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function y(e){return null!==e&&"object"==typeof e&&!!e[o]}function g(e,t){return function(e,t){if(!function(e){return void 0!==e}(e))throw m("not undefined",e,t)}(e,t),e}function p(e){return Array.isArray(e)||"string"==typeof e}function h(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||y(e)||f(e))}function d(e){return p(e)||h(e)}function f(e){return null!==e&&"object"==typeof e&&!!e["^^re^^"]}function v(e,t){if(!function(e){return"number"==typeof e||!!d(e)||!!y(e)}(e))throw m("FunctionLike",e,t)}function x(e,t={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(t.integer&&!Number.isInteger(e))&&(!(t.finite&&!Number.isFinite(e))&&((!t.zero||0===e)&&((!t.nonZero||0!==e)&&(!(t.positive&&e<=0)&&(!(t.negative&&e>=0)&&(!(t.nonPositive&&e>0)&&(!(t.nonNegative&&e<0)&&(!("number"==typeof t.gt&&e<=t.gt)&&(!("number"==typeof t.gte&&e<t.gte)&&(!("number"==typeof t.lt&&e>=t.lt)&&!("number"==typeof t.lte&&e>t.lte)))))))))))))}function $(e,t,s={}){if(!function(e,t={}){return!("string"!=typeof e||t.nonEmpty&&0===e.length||t.char&&1!==e.length)}(e,s))throw m(""+(s.nonEmpty?"non empty string":s.char?"character":"string"),e,t)}function w(e,t,s={}){return $(e,t,s),e}function b(e,t){if(!function(e){return"string"==typeof e||"number"==typeof e}(e))throw m("string or number",e,t)}function E(e,s,r){if(b(e,r),b(s,r),"string"==typeof e&&"string"==typeof s)return e<s?-1:e>s?1:0;if("number"==typeof e&&"number"==typeof s)return Math.sign(e-s);throw new t(`Cannot compare values of different types: ${typeof e} and ${typeof s}`,r)}function A(e,t,s){if(e===t)return!0;if("number"==typeof e&&"number"==typeof t)return function(e,t,s=N){if(e===t)return!0;const r=Math.abs(e-t);if(0===e||0===t||r<s)return r<s;const a=Math.abs(e),n=Math.abs(t);return r/(a+n)<s}(e,t);if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1)if(!A(g(e[r],s),g(t[r],s),s))return!1;return!0}if(f(e)&&f(t))return e.s===t.s&&e.f===t.f;if(c(e)&&c(t)){const r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;for(let a=0;a<r.length;a+=1){const n=w(r[a],s);if(!A(e[n],t[n],s))return!1}return!0}return!1}const N=1e-10;const O=new WeakSet,S=new WeakSet,F=new WeakSet,I=new WeakSet,j=new WeakSet,J=new WeakSet,q=new WeakSet;function k(e,t){return e instanceof Promise?e.then(t):t(e)}function M(e,t){try{const s=e();return s instanceof Promise?s.catch(t):s}catch(e){return t(e)}}const C={"assert!=":{category:"assertion",description:"If $a is the same as $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert!= } = import(assertion);\ntry assert!=(0, 0, "Expected different values") catch (e) e.message end',"let { assert!= } = import(assertion);\ntry assert!=(0, 0) catch (e) e.message end","let { assert!= } = import(assertion);\ntry 0 assert!= 0 catch (e) e.message end","let { assert!= } = import(assertion);\ntry assert!=(0, 1) catch (e) e.message end"],seeAlso:["assertion.assert="],hideOperatorForm:!0},"assert=":{category:"assertion",description:"If $a is not structural equal to $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert= } = import(assertion);\ntry assert=({ "a": 1 }, { "a": 2 }, "Expected equal values") catch (e) e.message end','let { assert= } = import(assertion);\ntry assert=({ "a": 1 }, { "a": 2 }) catch (e) e.message end','let { assert= } = import(assertion);\ntry assert=({ "a": 1 }, { "a": 1 }) catch (e) e.message end'],seeAlso:["assertion.assert!="],hideOperatorForm:!0},"assert-gt":{category:"assertion",description:"If $a is not greater than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-gt } = import(assertion);\ntry assert-gt(0, 1, "Expected greater value") catch (e) e.message end',"let { assert-gt } = import(assertion);\ntry assert-gt(0, 0) catch (e) e.message end","let { assert-gt } = import(assertion);\ntry assert-gt(1, 0) catch (e) e.message end"],seeAlso:["assertion.assert-lt","assertion.assert-gte","assertion.assert-lte"],hideOperatorForm:!0},"assert-lt":{category:"assertion",description:"If $a is not less than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-lt } = import(assertion);\ntry assert-lt(1, 0, "Expected smaller value value") catch (e) e.message end',"let { assert-lt } = import(assertion);\ntry assert-lt(1, 1) catch (e) e.message end","let { assert-lt } = import(assertion);\ntry assert-lt(0, 1) catch (e) e.message end"],seeAlso:["assertion.assert-gt","assertion.assert-lte","assertion.assert-gte"],hideOperatorForm:!0},"assert-gte":{category:"assertion",description:"If $a is less than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-gte } = import(assertion);\ntry assert-gte(0, 1, "Expected greater value") catch (e) e.message end',"let { assert-gte } = import(assertion);\ntry assert-gte(0, 1) catch (e) e.message end","let { assert-gte } = import(assertion);\ntry assert-gte(1, 1) catch (e) e.message end"],seeAlso:["assertion.assert-lte","assertion.assert-gt","assertion.assert-lt"],hideOperatorForm:!0},"assert-lte":{category:"assertion",description:"If $a is grater than $b it throws `AssertionError`.",returns:{type:"null"},args:{a:{type:"any"},b:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","message"]}],examples:['let { assert-lte } = import(assertion);\ntry assert-lte(1, 0, "Expected smaller value value") catch (e) e.message end',"let { assert-lte } = import(assertion);\ntry assert-lte(1, 0) catch (e) e.message end","let { assert-lte } = import(assertion);\ntry assert-lte(1, 1) catch (e) e.message end"],seeAlso:["assertion.assert-gte","assertion.assert-lt","assertion.assert-gt"],hideOperatorForm:!0},"assert-true":{category:"assertion",description:"If $value is not `true` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-true } = import(assertion);\ntry assert-true(false, "Expected true") catch (e) e.message end',"let { assert-true } = import(assertion);\ntry assert-true(false) catch (e) e.message end","let { assert-true } = import(assertion);\ntry assert-true(true) catch (e) e.message end"],seeAlso:["assertion.assert-false","assertion.assert-truthy","assertion.assert-falsy","assert","assertion.assert-boolean"],hideOperatorForm:!0},"assert-false":{category:"assertion",description:"If $value is not `false` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-false } = import(assertion);\ntry assert-false(true, "Expected false") catch (e) e.message end',"let { assert-false } = import(assertion);\ntry assert-false(true) catch (e) e.message end","let { assert-false } = import(assertion);\ntry assert-false(false) catch (e) e.message end"],seeAlso:["assertion.assert-true","assertion.assert-falsy","assertion.assert-truthy","assertion.assert-boolean"],hideOperatorForm:!0},"assert-truthy":{category:"assertion",description:"If $value is not `truthy` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-truthy } = import(assertion);\ntry assert-truthy(false, "Expected truthy") catch (e) e.message end',"let { assert-truthy } = import(assertion);\ntry assert-truthy(false) catch (e) e.message end","let { assert-truthy } = import(assertion);\ntry assert-truthy(0) catch (e) e.message end","let { assert-truthy } = import(assertion);\ntry assert-truthy(null) catch (e) e.message end",'let { assert-truthy } = import(assertion);\ntry assert-truthy("") catch (e) e.message end',"let { assert-truthy } = import(assertion);\ntry assert-truthy(true) catch (e) e.message end","let { assert-truthy } = import(assertion);\ntry assert-truthy(1) catch (e) e.message end",'let { assert-truthy } = import(assertion);\ntry assert-truthy("x") catch (e) e.message end',"let { assert-truthy } = import(assertion);\ntry assert-truthy([]) catch (e) e.message end","let { assert-truthy } = import(assertion);\ntry assert-truthy(nd) catch (e) e.message end"],seeAlso:["assertion.assert-falsy","assertion.assert-true","assertion.assert-false","assert","assertion.assert-null"],hideOperatorForm:!0},"assert-falsy":{category:"assertion",description:"If $value is not `falsy` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-falsy } = import(assertion);\ntry assert-falsy(true, "Expected falsy") catch (e) e.message end','let { assert-falsy } = import(assertion);\ntry assert-falsy("x") catch (e) e.message end',"let { assert-falsy } = import(assertion);\ntry assert-falsy([]) catch (e) e.message end","let { assert-falsy } = import(assertion);\ntry assert-falsy(nd) catch (e) e.message end","let { assert-falsy } = import(assertion);\ntry assert-falsy(1) catch (e) e.message end","let { assert-falsy } = import(assertion);\ntry assert-falsy(false) catch (e) e.message end","let { assert-falsy } = import(assertion);\ntry assert-falsy(0) catch (e) e.message end","let { assert-falsy } = import(assertion);\ntry assert-falsy(null) catch (e) e.message end",'let { assert-falsy } = import(assertion);\ntry assert-falsy("") catch (e) e.message end'],seeAlso:["assertion.assert-truthy","assertion.assert-false","assertion.assert-true","assertion.assert-null"],hideOperatorForm:!0},"assert-null":{category:"assertion",description:"If $value is not `null` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-null } = import(assertion);\ntry assert-null(null) catch (e) e.message end",'let { assert-null } = import(assertion);\ntry assert-null(true, "Expected null") catch (e) e.message end','let { assert-null } = import(assertion);\ntry assert-null("x") catch (e) e.message end',"let { assert-null } = import(assertion);\ntry assert-null([]) catch (e) e.message end","let { assert-null } = import(assertion);\ntry assert-null(nd) catch (e) e.message end","let { assert-null } = import(assertion);\ntry assert-null(1) catch (e) e.message end","let { assert-null } = import(assertion);\ntry assert-null(false) catch (e) e.message end","let { assert-null } = import(assertion);\ntry assert-null(0) catch (e) e.message end",'let { assert-null } = import(assertion);\ntry assert-null("") catch (e) e.message end'],seeAlso:["assertion.assert-truthy","assertion.assert-falsy"],hideOperatorForm:!0},"assert-throws":{category:"assertion",description:"If $fun does not throw, it throws `AssertionError`.",returns:{type:"null"},args:{fun:{type:"function"},message:{type:"string"}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","message"]}],examples:['let { assert-throws } = import(assertion);\nassert-throws(-> throw("Error"))','let { assert-throws } = import(assertion);\ntry assert-throws(-> identity("Error")) catch (e) e.message end'],seeAlso:["assertion.assert-throws-error","assertion.assert-not-throws"],hideOperatorForm:!0},"assert-throws-error":{category:"assertion",description:"If $fun does not throw $error-message, it throws `AssertionError`.",returns:{type:"null"},args:{fun:{type:"function"},"error-message":{type:"string"},message:{type:"string"}},variants:[{argumentNames:["value","error-message"]},{argumentNames:["value","error-message","message"]}],examples:['let { assert-throws-error } = import(assertion);\ntry assert-throws-error(-> throw("Error"), "Error") catch (e) e.message end','let { assert-throws-error } = import(assertion);\ntry assert-throws-error(-> identity("Error"), "Error") catch (e) e.message end'],seeAlso:["assertion.assert-throws","assertion.assert-not-throws"],hideOperatorForm:!0},"assert-not-throws":{category:"assertion",description:"If $fun throws, it throws `AssertionError`.",returns:{type:"null"},args:{fun:{type:"function"},message:{type:"string"}},variants:[{argumentNames:["fun"]},{argumentNames:["fun","message"]}],examples:['let { assert-not-throws } = import(assertion);\ntry assert-not-throws(-> identity("Error")) catch (e) e.message end','let { assert-not-throws } = import(assertion);\ntry assert-not-throws(-> throw("Error")) catch (e) e.message end'],seeAlso:["assertion.assert-throws","assertion.assert-throws-error"],hideOperatorForm:!0},"assert-array":{category:"assertion",description:"If $value is not an `array` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-array } = import(assertion);\ntry assert-array([1, 2, 3]) catch (e) e.message end",'let { assert-array } = import(assertion);\ntry assert-array("string") catch (e) e.message end','let { assert-array } = import(assertion);\ntry assert-array(42, "Expected an array") catch (e) e.message end'],seeAlso:["assertion.assert-object","assertion.assert-collection","assertion.assert-sequence"],hideOperatorForm:!0},"assert-boolean":{category:"assertion",description:"If $value is not a `boolean` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-boolean } = import(assertion);\ntry assert-boolean(true) catch (e) e.message end","let { assert-boolean } = import(assertion);\ntry assert-boolean(false) catch (e) e.message end",'let { assert-boolean } = import(assertion);\ntry assert-boolean(1, "Expected a boolean") catch (e) e.message end'],seeAlso:["assertion.assert-true","assertion.assert-false","assertion.assert-number","assertion.assert-string"],hideOperatorForm:!0},"assert-collection":{category:"assertion",description:"If $value is not a `collection` (array, object, or string) it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-collection } = import(assertion);\ntry assert-collection([1, 2]) catch (e) e.message end","let { assert-collection } = import(assertion);\ntry assert-collection({ a: 1 }) catch (e) e.message end",'let { assert-collection } = import(assertion);\ntry assert-collection("hello") catch (e) e.message end','let { assert-collection } = import(assertion);\ntry assert-collection(42, "Expected a collection") catch (e) e.message end'],seeAlso:["assertion.assert-sequence","assertion.assert-array","assertion.assert-object"],hideOperatorForm:!0},"assert-function":{category:"assertion",description:"If $value is not a `function` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-function } = import(assertion);\ntry assert-function(-> $ + 1) catch (e) e.message end",'let { assert-function } = import(assertion);\ntry assert-function(42, "Expected a function") catch (e) e.message end'],seeAlso:["assertion.assert-number","assertion.assert-string"],hideOperatorForm:!0},"assert-grid":{category:"assertion",description:"If $value is not a `grid` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-grid } = import(assertion);\ntry assert-grid([[1, 2], [3, 4]]) catch (e) e.message end",'let { assert-grid } = import(assertion);\ntry assert-grid([1, 2], "Expected a grid") catch (e) e.message end'],seeAlso:["assertion.assert-matrix","assertion.assert-vector"],hideOperatorForm:!0},"assert-integer":{category:"assertion",description:"If $value is not an `integer` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-integer } = import(assertion);\ntry assert-integer(42) catch (e) e.message end",'let { assert-integer } = import(assertion);\ntry assert-integer(3.14, "Expected an integer") catch (e) e.message end'],seeAlso:["assertion.assert-number"],hideOperatorForm:!0},"assert-matrix":{category:"assertion",description:"If $value is not a `matrix` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-matrix } = import(assertion);\ntry assert-matrix([[1, 2], [3, 4]]) catch (e) e.message end",'let { assert-matrix } = import(assertion);\ntry assert-matrix([1, 2], "Expected a matrix") catch (e) e.message end'],seeAlso:["assertion.assert-vector","assertion.assert-grid"],hideOperatorForm:!0},"assert-number":{category:"assertion",description:"If $value is not a `number` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-number } = import(assertion);\ntry assert-number(42) catch (e) e.message end",'let { assert-number } = import(assertion);\ntry assert-number("hello", "Expected a number") catch (e) e.message end'],seeAlso:["assertion.assert-integer","assertion.assert-boolean","assertion.assert-string","assertion.assert-function"],hideOperatorForm:!0},"assert-object":{category:"assertion",description:"If $value is not an `object` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-object } = import(assertion);\ntry assert-object({ a: 1 }) catch (e) e.message end",'let { assert-object } = import(assertion);\ntry assert-object([1, 2], "Expected an object") catch (e) e.message end'],seeAlso:["assertion.assert-array","assertion.assert-collection"],hideOperatorForm:!0},"assert-regexp":{category:"assertion",description:"If $value is not a `regexp` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-regexp } = import(assertion);\ntry assert-regexp(#"^start") catch (e) e.message end','let { assert-regexp } = import(assertion);\ntry assert-regexp("hello", "Expected a regexp") catch (e) e.message end'],seeAlso:["assertion.assert-string"],hideOperatorForm:!0},"assert-sequence":{category:"assertion",description:"If $value is not a `sequence` (array or string) it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-sequence } = import(assertion);\ntry assert-sequence([1, 2]) catch (e) e.message end",'let { assert-sequence } = import(assertion);\ntry assert-sequence("hello") catch (e) e.message end','let { assert-sequence } = import(assertion);\ntry assert-sequence({ a: 1 }, "Expected a sequence") catch (e) e.message end'],seeAlso:["assertion.assert-collection","assertion.assert-array"],hideOperatorForm:!0},"assert-string":{category:"assertion",description:"If $value is not a `string` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:['let { assert-string } = import(assertion);\ntry assert-string("hello") catch (e) e.message end','let { assert-string } = import(assertion);\ntry assert-string(42, "Expected a string") catch (e) e.message end'],seeAlso:["assertion.assert-number","assertion.assert-boolean","assertion.assert-regexp","assertion.assert-function"],hideOperatorForm:!0},"assert-vector":{category:"assertion",description:"If $value is not a `vector` it throws `AssertionError`.",returns:{type:"null"},args:{value:{type:"any"},message:{type:"string"}},variants:[{argumentNames:["value"]},{argumentNames:["value","message"]}],examples:["let { assert-vector } = import(assertion);\ntry assert-vector([1, 2, 3]) catch (e) e.message end",'let { assert-vector } = import(assertion);\ntry assert-vector(["a", "b"], "Expected a vector") catch (e) e.message end'],seeAlso:["assertion.assert-matrix","assertion.assert-grid"],hideOperatorForm:!0}},P={"assert=":{evaluate:([e,t,r],a)=>{if(void 0!==r&&($(r,a),r=` ${r}`),r??="",!A(g(e,a),g(t,a),a))throw new s(`Expected ${JSON.stringify(e,null,2)} to deep equal ${JSON.stringify(t,null,2)}.${r}`,a);return null},arity:{min:2,max:3}},"assert!=":{evaluate:([e,t,r],a)=>{if(void 0!==r&&($(r,a),r=` ${r}`),r??="",A(g(e,a),g(t,a),a))throw new s(`Expected ${JSON.stringify(e)} not to deep equal ${JSON.stringify(t)}.${r}`,a);return null},arity:{min:2,max:3}},"assert-gt":{evaluate:([e,t,r],a)=>{if(b(e,a),b(t,a),void 0!==r&&($(r,a),r=` ${r}`),r??="",E(e,t,a)<=0)throw new s(`Expected ${e} to be grater than ${t}.${r}`,a);return null},arity:{min:2,max:3}},"assert-gte":{evaluate:([e,t,r],a)=>{if(b(e,a),b(t,a),void 0!==r&&($(r,a),r=` ${r}`),r??="",E(e,t,a)<0)throw new s(`Expected ${e} to be grater than or equal to ${t}.${r}`,a);return null},arity:{min:2,max:3}},"assert-lt":{evaluate:([e,t,r],a)=>{if(b(e,a),b(t,a),void 0!==r&&($(r,a),r=` ${r}`),r??="",E(e,t,a)>=0)throw new s(`Expected ${e} to be less than ${t}.${r}`,a);return null},arity:{min:2,max:3}},"assert-lte":{evaluate:([e,t,r],a)=>{if(b(e,a),b(t,a),void 0!==r&&($(r,a),r=` ${r}`),r??="",E(e,t,a)>0)throw new s(`Expected ${e} to be less than or equal to ${t}.${r}`,a);return null},arity:{min:2,max:3}},"assert-true":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!0!==e)throw new s(`Expected ${e} to be true.${t}`,r);return null},arity:{min:1,max:2}},"assert-false":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!1!==e)throw new s(`Expected ${e} to be false.${t}`,r);return null},arity:{min:1,max:2}},"assert-truthy":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!e)throw new s(`Expected ${e} to be truthy.${t}`,r);return null},arity:{min:1,max:2}},"assert-falsy":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",e)throw new s(`Expected ${e} to be falsy.${t}`,r);return null},arity:{min:1,max:2}},"assert-null":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",null!==e)throw new s(`Expected ${e} to be null.${t}`,r);return null},arity:{min:1,max:2}},"assert-throws":{evaluate:([e,t],r,a,{executeFunction:n})=>(void 0!==t&&($(t,r),t=` ${t}`),t??="",v(e,r),M(()=>k(n(e,[],a,r),()=>{throw new s(`Expected function to throw.${t}`,r)}),()=>null)),arity:{min:1,max:2}},"assert-throws-error":{evaluate:([e,t,r],a,n,{executeFunction:o})=>(void 0!==r&&($(r,a),r=` ${r}`),r??="",$(t,a),v(e,a),M(()=>k(o(e,[],n,a),()=>{throw new s(`Expected function to throw "${t}".${r}`,a)}),e=>{const n=e.shortMessage;if(n!==t)throw new s(`Expected function to throw "${t}", but thrown "${n}".${r}`,a);return null})),arity:{min:2,max:3}},"assert-not-throws":{evaluate:([e,t],r,a,{executeFunction:n})=>(void 0!==t&&($(t,r),t=` ${t}`),t??="",v(e,r),M(()=>k(n(e,[],a,r),()=>null),()=>{throw new s(`Expected function not to throw.${t}`,r)})),arity:{min:1,max:2}},"assert-array":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!Array.isArray(e))throw new s(`Expected ${JSON.stringify(e)} to be an array.${t}`,r);return null},arity:{min:1,max:2}},"assert-boolean":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="","boolean"!=typeof e)throw new s(`Expected ${JSON.stringify(e)} to be a boolean.${t}`,r);return null},arity:{min:1,max:2}},"assert-collection":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!d(e))throw new s(`Expected ${JSON.stringify(e)} to be a collection.${t}`,r);return null},arity:{min:1,max:2}},"assert-function":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!y(e))throw new s(`Expected ${JSON.stringify(e)} to be a function.${t}`,r);return null},arity:{min:1,max:2}},"assert-grid":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!function(e){if(!Array.isArray(e))return!1;if(J.has(e))return!0;if(q.has(e))return!1;if(0===e.length)return q.add(e),!1;if(!Array.isArray(e[0]))return q.add(e),!1;const t=e[0].length;for(const s of e.slice(1)){if(!Array.isArray(s))return q.add(e),!1;if(s.length!==t)return q.add(e),!1}return O.add(e),J.add(e),!0}(e))throw new s(`Expected ${JSON.stringify(e)} to be a grid.${t}`,r);return null},arity:{min:1,max:2}},"assert-integer":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="","number"!=typeof e||!x(e,{integer:!0}))throw new s(`Expected ${JSON.stringify(e)} to be an integer.${t}`,r);return null},arity:{min:1,max:2}},"assert-matrix":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!function(e){if(!Array.isArray(e))return!1;if(I.has(e))return!0;if(j.has(e))return!1;if(0===e.length)return j.add(e),!1;if(!Array.isArray(e[0])||0===e[0].length)return j.add(e),!1;const t=e[0].length;for(const s of e)if(!Array.isArray(s)||s.length!==t||s.some(e=>!x(e)))return j.add(e),!1;return O.add(e),J.add(e),I.add(e),!0}(e))throw new s(`Expected ${JSON.stringify(e)} to be a matrix.${t}`,r);return null},arity:{min:1,max:2}},"assert-number":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="","number"!=typeof e)throw new s(`Expected ${JSON.stringify(e)} to be a number.${t}`,r);return null},arity:{min:1,max:2}},"assert-object":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!h(e))throw new s(`Expected ${JSON.stringify(e)} to be an object.${t}`,r);return null},arity:{min:1,max:2}},"assert-regexp":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!f(e))throw new s(`Expected ${JSON.stringify(e)} to be a regexp.${t}`,r);return null},arity:{min:1,max:2}},"assert-sequence":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",!p(e))throw new s(`Expected ${JSON.stringify(e)} to be a sequence.${t}`,r);return null},arity:{min:1,max:2}},"assert-string":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="","string"!=typeof e)throw new s(`Expected ${JSON.stringify(e)} to be a string.${t}`,r);return null},arity:{min:1,max:2}},"assert-vector":{evaluate:([e,t],r)=>{if(void 0!==t&&($(t,r),t=` ${t}`),t??="",a=e,!Array.isArray(a)||!S.has(a)&&(F.has(a)||(a.every(e=>x(e))?(O.add(a),S.add(a),0):(F.add(a),1))))throw new s(`Expected ${JSON.stringify(e)} to be a vector.${t}`,r);var a;return null},arity:{min:1,max:2}}};for(const[e,t]of Object.entries(C))P[e]&&(P[e].docs=t);const W={name:"assertion",functions:P};export{W as assertModule}; //# sourceMappingURL=assertion.esm.js.map