parent
252e795a65
commit
96b66f1413
@ -0,0 +1,8 @@ |
|||||||
|
import { L, P, _ } from './core'; |
||||||
|
import { String, toString } from './string'; |
||||||
|
|
||||||
|
export const log: L<<T extends P>(s: String) => L<(p: T) => T>> |
||||||
|
= _(s => _(p => { |
||||||
|
console.log(toString(s)); |
||||||
|
return p; |
||||||
|
})); |
||||||
@ -1,199 +1,214 @@ |
|||||||
import { describe, expect, it } from '@jest/globals'; |
import { describe, expect, it } from '@jest/globals'; |
||||||
import { toNOrd as $o, NOrd } from '../src/ord'; |
import { toNOrd as $o, NOrd } from '../src/ord'; |
||||||
import { toBoolean as $b, fromBoolean as _b } from '../src/bool'; |
import { toBoolean as $b, fromBoolean as _b } from '../src/bool'; |
||||||
import { fromNumber as _n } from '../src/num'; |
import { fromNumber as _n } from '../src/byte'; |
||||||
import { toChar as $, fromChar as _, cmp, eq, ge, gt, le, lt } from '../src/char'; |
import { toChar as $c, fromChar as _c, cmp, eq, ge, gt, le, lt, show } from '../src/char'; |
||||||
|
import { toString as $s } from '../src/string'; |
||||||
|
|
||||||
describe('Char', () => { |
describe('Char', () => { |
||||||
describe('toChar', () => { |
describe('toChar', () => { |
||||||
it('converts "0"', () => { |
it('converts "0"', () => { |
||||||
expect($(_n(48))).toBe('0'); |
expect($c(_n(48))).toBe('0'); |
||||||
}); |
}); |
||||||
|
|
||||||
it('converts "a"', () => { |
it('converts "a"', () => { |
||||||
expect($(_n(97))).toBe('a'); |
expect($c(_n(97))).toBe('a'); |
||||||
}); |
}); |
||||||
|
|
||||||
it('converts "Z"', () => { |
it('converts "Z"', () => { |
||||||
expect($(_n(90))).toBe('Z'); |
expect($c(_n(90))).toBe('Z'); |
||||||
}); |
}); |
||||||
|
|
||||||
it('converts "-"', () => { |
it('converts "-"', () => { |
||||||
expect($(_n(45))).toBe('-'); |
expect($c(_n(45))).toBe('-'); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|
||||||
describe('fromChar', () => { |
describe('fromChar', () => { |
||||||
it('converts "0"', () => { |
it('converts "0"', () => { |
||||||
expect($(_('0'))).toBe('0'); |
expect($c(_c('0'))).toBe('0'); |
||||||
}); |
}); |
||||||
|
|
||||||
it('converts "a"', () => { |
it('converts "a"', () => { |
||||||
expect($(_('a'))).toBe('a'); |
expect($c(_c('a'))).toBe('a'); |
||||||
}); |
}); |
||||||
|
|
||||||
it('converts "Z"', () => { |
it('converts "Z"', () => { |
||||||
expect($(_('Z'))).toBe('Z'); |
expect($c(_c('Z'))).toBe('Z'); |
||||||
}); |
}); |
||||||
|
|
||||||
it('converts "-"', () => { |
it('converts "-"', () => { |
||||||
expect($(_('-'))).toBe('-'); |
expect($c(_c('-'))).toBe('-'); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|
||||||
describe('cmp', () => { |
describe('cmp', () => { |
||||||
it('"0" cmp "0" is EQ', () => { |
it('"0" cmp "0" is EQ', () => { |
||||||
expect($o(cmp._(_('0'))._(_('0')))).toBe(NOrd.EQ); |
expect($o(cmp._(_c('0'))._(_c('0')))).toBe(NOrd.EQ); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"0" cmp "a" is LT', () => { |
it('"0" cmp "a" is LT', () => { |
||||||
expect($o(cmp._(_('0'))._(_('a')))).toBe(NOrd.LT); |
expect($o(cmp._(_c('0'))._(_c('a')))).toBe(NOrd.LT); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"a" cmp "0" is GT', () => { |
it('"a" cmp "0" is GT', () => { |
||||||
expect($o(cmp._(_('a'))._(_('0')))).toBe(NOrd.GT); |
expect($o(cmp._(_c('a'))._(_c('0')))).toBe(NOrd.GT); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" cmp "z" is EQ', () => { |
it('"z" cmp "z" is EQ', () => { |
||||||
expect($o(cmp._(_('z'))._(_('z')))).toBe(NOrd.EQ); |
expect($o(cmp._(_c('z'))._(_c('z')))).toBe(NOrd.EQ); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" cmp "-" is GT', () => { |
it('"z" cmp "-" is GT', () => { |
||||||
expect($o(cmp._(_('z'))._(_('-')))).toBe(NOrd.GT); |
expect($o(cmp._(_c('z'))._(_c('-')))).toBe(NOrd.GT); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"-" cmp "z" is LT', () => { |
it('"-" cmp "z" is LT', () => { |
||||||
expect($o(cmp._(_('-'))._(_('z')))).toBe(NOrd.LT); |
expect($o(cmp._(_c('-'))._(_c('z')))).toBe(NOrd.LT); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|
||||||
describe('lt', () => { |
describe('lt', () => { |
||||||
it('"0" lt "0" is False', () => { |
it('"0" lt "0" is False', () => { |
||||||
expect($b(lt._(_('0'))._(_('0')))).toBe(false); |
expect($b(lt._(_c('0'))._(_c('0')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"0" lt "a" is True', () => { |
it('"0" lt "a" is True', () => { |
||||||
expect($b(lt._(_('0'))._(_('a')))).toBe(true); |
expect($b(lt._(_c('0'))._(_c('a')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"a" lt "0" is False', () => { |
it('"a" lt "0" is False', () => { |
||||||
expect($b(lt._(_('a'))._(_('0')))).toBe(false); |
expect($b(lt._(_c('a'))._(_c('0')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" lt "z" is False', () => { |
it('"z" lt "z" is False', () => { |
||||||
expect($b(lt._(_('z'))._(_('z')))).toBe(false); |
expect($b(lt._(_c('z'))._(_c('z')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" lt "-" is False', () => { |
it('"z" lt "-" is False', () => { |
||||||
expect($b(lt._(_('z'))._(_('-')))).toBe(false); |
expect($b(lt._(_c('z'))._(_c('-')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"-" lt "z" is True', () => { |
it('"-" lt "z" is True', () => { |
||||||
expect($b(lt._(_('-'))._(_('z')))).toBe(true); |
expect($b(lt._(_c('-'))._(_c('z')))).toBe(true); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|
||||||
describe('le', () => { |
describe('le', () => { |
||||||
it('"0" le "0" is True', () => { |
it('"0" le "0" is True', () => { |
||||||
expect($b(le._(_('0'))._(_('0')))).toBe(true); |
expect($b(le._(_c('0'))._(_c('0')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"0" le "a" is True', () => { |
it('"0" le "a" is True', () => { |
||||||
expect($b(le._(_('0'))._(_('a')))).toBe(true); |
expect($b(le._(_c('0'))._(_c('a')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"a" le "0" is False', () => { |
it('"a" le "0" is False', () => { |
||||||
expect($b(le._(_('a'))._(_('0')))).toBe(false); |
expect($b(le._(_c('a'))._(_c('0')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" le "z" is True', () => { |
it('"z" le "z" is True', () => { |
||||||
expect($b(le._(_('z'))._(_('z')))).toBe(true); |
expect($b(le._(_c('z'))._(_c('z')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" le "-" is False', () => { |
it('"z" le "-" is False', () => { |
||||||
expect($b(le._(_('z'))._(_('-')))).toBe(false); |
expect($b(le._(_c('z'))._(_c('-')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"-" le "z" is True', () => { |
it('"-" le "z" is True', () => { |
||||||
expect($b(le._(_('-'))._(_('z')))).toBe(true); |
expect($b(le._(_c('-'))._(_c('z')))).toBe(true); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|
||||||
describe('eq', () => { |
describe('eq', () => { |
||||||
it('"0" eq "0" is True', () => { |
it('"0" eq "0" is True', () => { |
||||||
expect($b(eq._(_('0'))._(_('0')))).toBe(true); |
expect($b(eq._(_c('0'))._(_c('0')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"0" eq "a" is False', () => { |
it('"0" eq "a" is False', () => { |
||||||
expect($b(eq._(_('0'))._(_('a')))).toBe(false); |
expect($b(eq._(_c('0'))._(_c('a')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"a" eq "0" is False', () => { |
it('"a" eq "0" is False', () => { |
||||||
expect($b(eq._(_('a'))._(_('0')))).toBe(false); |
expect($b(eq._(_c('a'))._(_c('0')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" eq "z" is True', () => { |
it('"z" eq "z" is True', () => { |
||||||
expect($b(eq._(_('z'))._(_('z')))).toBe(true); |
expect($b(eq._(_c('z'))._(_c('z')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" eq "-" is False', () => { |
it('"z" eq "-" is False', () => { |
||||||
expect($b(eq._(_('z'))._(_('-')))).toBe(false); |
expect($b(eq._(_c('z'))._(_c('-')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"-" eq "z" is False', () => { |
it('"-" eq "z" is False', () => { |
||||||
expect($b(eq._(_('-'))._(_('z')))).toBe(false); |
expect($b(eq._(_c('-'))._(_c('z')))).toBe(false); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|
||||||
describe('ge', () => { |
describe('ge', () => { |
||||||
it('"0" ge "0" is True', () => { |
it('"0" ge "0" is True', () => { |
||||||
expect($b(ge._(_('0'))._(_('0')))).toBe(true); |
expect($b(ge._(_c('0'))._(_c('0')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"0" ge "a" is False', () => { |
it('"0" ge "a" is False', () => { |
||||||
expect($b(ge._(_('0'))._(_('a')))).toBe(false); |
expect($b(ge._(_c('0'))._(_c('a')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"a" ge "0" is True', () => { |
it('"a" ge "0" is True', () => { |
||||||
expect($b(ge._(_('a'))._(_('0')))).toBe(true); |
expect($b(ge._(_c('a'))._(_c('0')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" ge "z" is True', () => { |
it('"z" ge "z" is True', () => { |
||||||
expect($b(ge._(_('z'))._(_('z')))).toBe(true); |
expect($b(ge._(_c('z'))._(_c('z')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" ge "-" is True', () => { |
it('"z" ge "-" is True', () => { |
||||||
expect($b(ge._(_('z'))._(_('-')))).toBe(true); |
expect($b(ge._(_c('z'))._(_c('-')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"-" ge "z" is False', () => { |
it('"-" ge "z" is False', () => { |
||||||
expect($b(ge._(_('-'))._(_('z')))).toBe(false); |
expect($b(ge._(_c('-'))._(_c('z')))).toBe(false); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|
||||||
describe('gt', () => { |
describe('gt', () => { |
||||||
it('"0" gt "0" is False', () => { |
it('"0" gt "0" is False', () => { |
||||||
expect($b(gt._(_('0'))._(_('0')))).toBe(false); |
expect($b(gt._(_c('0'))._(_c('0')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"0" gt "a" is False', () => { |
it('"0" gt "a" is False', () => { |
||||||
expect($b(gt._(_('0'))._(_('a')))).toBe(false); |
expect($b(gt._(_c('0'))._(_c('a')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"a" gt "0" is True', () => { |
it('"a" gt "0" is True', () => { |
||||||
expect($b(gt._(_('a'))._(_('0')))).toBe(true); |
expect($b(gt._(_c('a'))._(_c('0')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" gt "z" is False', () => { |
it('"z" gt "z" is False', () => { |
||||||
expect($b(gt._(_('z'))._(_('z')))).toBe(false); |
expect($b(gt._(_c('z'))._(_c('z')))).toBe(false); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"z" gt "-" is True', () => { |
it('"z" gt "-" is True', () => { |
||||||
expect($b(gt._(_('z'))._(_('-')))).toBe(true); |
expect($b(gt._(_c('z'))._(_c('-')))).toBe(true); |
||||||
}); |
}); |
||||||
|
|
||||||
it('"-" gt "z" is False', () => { |
it('"-" gt "z" is False', () => { |
||||||
expect($b(gt._(_('-'))._(_('z')))).toBe(false); |
expect($b(gt._(_c('-'))._(_c('z')))).toBe(false); |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
describe('show', () => { |
||||||
|
it('show "0" is "\'0\'"', () => { |
||||||
|
expect($s(show._(_c('0')))).toBe('\'0\''); |
||||||
|
}); |
||||||
|
|
||||||
|
it('show "a" is "\'a\'"', () => { |
||||||
|
expect($s(show._(_c('a')))).toBe('\'a\''); |
||||||
|
}); |
||||||
|
|
||||||
|
it('show "-" is "\'-\'"', () => { |
||||||
|
expect($s(show._(_c('-')))).toBe('\'-\''); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|||||||
Loading…
Reference in new issue