You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.2 KiB
106 lines
3.2 KiB
import { describe, expect, it } from '@jest/globals';
|
|
import { L, _, undef } from '../src/core';
|
|
import { toBoolean as $b } from '../src/bool';
|
|
import { toChar as $c, fromChar as _c, eq as eqc } from '../src/char';
|
|
import { toString as $s, Cons, Empty, String, fromString as _s, concat, eq } from '../src/string';
|
|
|
|
describe('String', () => {
|
|
const infinite: String = new L(() => Cons._(_c('a'))._(infinite).value);;
|
|
|
|
describe('toString', () => {
|
|
it('converts ""', () => {
|
|
expect($s(Empty)).toBe('');
|
|
});
|
|
|
|
it('converts "a"', () => {
|
|
expect($s(Cons._(_c('a'))._(Empty))).toBe('a');
|
|
});
|
|
|
|
it('converts "abc"', () => {
|
|
expect($s(Cons._(_c('a'))._(Cons._(_c('b'))._(Cons._(_c('c'))._(Empty))))).toBe('abc');
|
|
});
|
|
});
|
|
|
|
describe('fromString', () => {
|
|
it('converts ""', () => {
|
|
expect($s(_s(''))).toBe('');
|
|
});
|
|
|
|
it('converts "a"', () => {
|
|
expect($s(_s('a'))).toBe('a');
|
|
});
|
|
|
|
it('converts "2"', () => {
|
|
expect($s(_s('abc'))).toBe('abc');
|
|
});
|
|
});
|
|
|
|
describe('concat', () => {
|
|
it('"" concat "" is ""', () => {
|
|
expect(concat).toDeferEvaluationOf(Empty, Empty);
|
|
expect($s(concat._(Empty)._(Empty))).toBe('');
|
|
});
|
|
|
|
it('"a" concat "b" is "ab"', () => {
|
|
expect(concat).toDeferEvaluationOf(_s('a'), _s('b'));
|
|
expect($s(concat._(_s('a'))._(_s('b')))).toBe('ab');
|
|
});
|
|
|
|
it('"abc" concat "def" is "abcdef"', () => {
|
|
expect(concat).toDeferEvaluationOf(_s('abc'), _s('def'));
|
|
expect($s(concat._(_s('abc'))._(_s('def')))).toBe('abcdef');
|
|
});
|
|
|
|
it('handles infinite lists', () => {
|
|
expect($c(concat._(infinite)._(infinite)._(undef)._(_(x => _(_xs => x))))).toBe('a');
|
|
});
|
|
});
|
|
|
|
describe('eq', () => {
|
|
it('"" eq "" is True', () => {
|
|
expect(eq).toDeferEvaluationOf(eqc, _s(''), _s(''));
|
|
expect($b(eq._(_s(''))._(_s('')))).toBe(true);
|
|
});
|
|
|
|
it('"" eq "abc" is False', () => {
|
|
expect(eq).toDeferEvaluationOf(eqc, _s(''), _s("abc"));
|
|
expect($b(eq._(_s(''))._(_s("abc")))).toBe(false);
|
|
});
|
|
|
|
it('"abc" eq "" is False', () => {
|
|
expect(eq).toDeferEvaluationOf(eqc, _s("abc"), _s(''));
|
|
expect($b(eq._(_s("abc"))._(_s('')))).toBe(false);
|
|
});
|
|
|
|
it('"a" eq "abc" is False', () => {
|
|
expect(eq).toDeferEvaluationOf(eqc, _s('a'), _s("abc"));
|
|
expect($b(eq._(_s('a'))._(_s("abc")))).toBe(false);
|
|
});
|
|
|
|
it('"abc" eq "a" is False', () => {
|
|
expect(eq).toDeferEvaluationOf(eqc, _s("abc"), _s('a'));
|
|
expect($b(eq._(_s("abc"))._(_s('a')))).toBe(false);
|
|
});
|
|
|
|
|
|
it('"bca" eq "abc" is False', () => {
|
|
expect(eq).toDeferEvaluationOf(eqc, _s("bca"), _s("abc"));
|
|
expect($b(eq._(_s("bca"))._(_s("abc")))).toBe(false);
|
|
});
|
|
|
|
it('"abc" eq "bca" is False', () => {
|
|
expect(eq).toDeferEvaluationOf(eqc, _s("abc"), _s("bca"));
|
|
expect($b(eq._(_s("abc"))._(_s("bca")))).toBe(false);
|
|
});
|
|
|
|
it('"abc" eq "abc" is True', () => {
|
|
expect(eq).toDeferEvaluationOf(eqc, _s("abc"), _s("abc"));
|
|
expect($b(eq._(_s("abc"))._(_s("abc")))).toBe(true);
|
|
});
|
|
|
|
it('handles infinite lists', () => {
|
|
expect($b(eq._(infinite)._(_s("abc")))).toBe(false);
|
|
expect($b(eq._(_s("abc"))._(infinite))).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
|