-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ee7604
commit 808c6d2
Showing
13 changed files
with
445 additions
and
484 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
import test from 'node:test' | ||
import { describe, test } from 'node:test' | ||
import { equal } from 'node:assert/strict' | ||
import { toBase52, fromBase52 } from './base52.js' | ||
import { base52, base52Decode } from './base52.js' | ||
|
||
|
||
const tests = [ | ||
[0, 'A'], | ||
[1, 'B'], | ||
[25, 'Z'], | ||
[26, 'a'], | ||
[51, 'z'], | ||
[52, 'BA'], | ||
[2 ** 30, 'CqsVtM'] | ||
] | ||
|
||
tests.forEach(([input, expected]) => | ||
test(`base52(${input}) => ${expected}`, () => | ||
equal(toBase52(input), expected))) | ||
describe('base52', () => { | ||
const tests = [ | ||
[0, 'A'], | ||
[1, 'B'], | ||
[25, 'Z'], | ||
[26, 'a'], | ||
[51, 'z'], | ||
[52, 'BA'], | ||
[2 ** 30, 'CqsVtM'] | ||
] | ||
|
||
tests.forEach(([expected, input]) => | ||
test(`base52Decode(${input}) => ${expected}`, () => | ||
equal(fromBase52(input), expected))) | ||
tests.forEach(([input, expected]) => | ||
test(`base52(${input}) => ${expected}`, () => | ||
equal(base52(input), expected))) | ||
|
||
tests.forEach(([expected, input]) => | ||
test(`base52Decode(${input}) => ${expected}`, () => | ||
equal(base52Decode(input), expected))) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
import test from 'node:test' | ||
import { describe, test } from 'node:test' | ||
import { equal, throws } from 'node:assert/strict' | ||
import { isDarkColor } from './is-dark-color.js' | ||
|
||
const isTrue = color => equal(isDarkColor(color), true) | ||
const isFalse = color => equal(isDarkColor(color), false) | ||
|
||
test('Requires 6 hex digits', () => | ||
throws(() => isDarkColor('#abc'))) | ||
describe('isDarkColor', () => { | ||
const isTrue = color => equal(isDarkColor(color), true) | ||
const isFalse = color => equal(isDarkColor(color), false) | ||
|
||
test('is dark color', () => { | ||
isTrue('#000000') | ||
isTrue('#123456') | ||
isTrue('#555555') | ||
test('Requires 6 hex digits', () => | ||
throws(() => isDarkColor('#abc'))) | ||
|
||
isFalse('#aaaaaa') | ||
isFalse('#abcdef') | ||
isFalse('#ffffff') | ||
test('is dark color', () => { | ||
isTrue('#000000') | ||
isTrue('#123456') | ||
isTrue('#555555') | ||
|
||
isFalse('#aaaaaa') | ||
isFalse('#abcdef') | ||
isFalse('#ffffff') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,6 @@ | |
"node": ">=18" | ||
}, | ||
"scripts": { | ||
"test": "node _testAll.js" | ||
"test": "node --test" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,59 @@ | ||
import test from 'node:test' | ||
import { describe, test } from 'node:test' | ||
import { throws, equal } from 'node:assert/strict' | ||
import { proxyFieldNames } from './proxyFieldNames.js' | ||
|
||
|
||
function prodTest(a, b) { | ||
_test('PrefixNotUsed', a, b, true) | ||
} | ||
describe('Proxy Field Names', () => { | ||
function prodTest(a, b) { _test('PrefixNotUsed', a, b, true) } | ||
function devTest(prefix, a, b) { _test(prefix, a, b, false) } | ||
|
||
function _test(prefix, a, b, isProduction) { | ||
const proxy = proxyFieldNames(prefix, a, isProduction) | ||
for (const k in proxy) | ||
equal(proxy[k], b[k]) | ||
} | ||
|
||
function devTest(prefix, a, b) { | ||
_test(prefix, a, b, false) | ||
} | ||
console.log('proxyFields') | ||
|
||
function _test(prefix, a, b, isProduction) { | ||
const proxy = proxyFieldNames(prefix, a, isProduction) | ||
for (const k in proxy) | ||
equal(proxy[k], b[k]) | ||
} | ||
test('Dev prefixes', () => | ||
devTest('PRE', | ||
{ x: null, y: null }, | ||
{ x: 'PRE_x', y: 'PRE_y' })) | ||
|
||
console.log('proxyFields') | ||
test('Dev prefixes ignoring pre-baked values', () => | ||
devTest('PRE', | ||
{ x: 'val0', y: 1 }, | ||
{ x: 'PRE_x', y: 'PRE_y' })) | ||
|
||
test('Dev prefixes', () => | ||
devTest('PRE', | ||
{ x: null, y: null }, | ||
{ x: 'PRE_x', y: 'PRE_y' })) | ||
|
||
test('Dev prefixes ignoring pre-baked values', () => | ||
devTest('PRE', | ||
{ x: 'val0', y: 1 }, | ||
{ x: 'PRE_x', y: 'PRE_y' })) | ||
test('Prod uses pre-baked values', () => | ||
prodTest( | ||
{ x: 'val0', y: 1 }, | ||
{ x: 'val0', y: 1 })) | ||
|
||
test('Prod generates base52 values', () => | ||
prodTest( | ||
{ x: null, y: null }, | ||
{ x: 'A', y: 'B' })) | ||
|
||
test('Prod uses pre-baked values', () => | ||
prodTest( | ||
{ x: 'val0', y: 1 }, | ||
{ x: 'val0', y: 1 })) | ||
|
||
test('Prod generates base52 values', () => | ||
prodTest( | ||
{ x: null, y: null }, | ||
{ x: 'A', y: 'B' })) | ||
test('Repeated values throw', () => | ||
throws(() => proxyFieldNames('PRE', { | ||
x: 0, | ||
y: 0 | ||
}), /value "0" is repeated/)) | ||
|
||
|
||
test('Repeated values throw', () => | ||
throws(() => proxyFieldNames('PRE', { | ||
x: 0, | ||
y: 0 | ||
}), /value "0" is repeated/)) | ||
test('Mixing null and numeric values throws', () => | ||
throws(() => proxyFieldNames('PRE', { | ||
x: 0, | ||
y: null | ||
}), /Mixing null and numeric values in: "PRE"/)) | ||
|
||
|
||
test('Mixing null and numeric values throws', () => | ||
throws(() => proxyFieldNames('PRE', { | ||
x: 0, | ||
y: null | ||
}), /Mixing null and numeric values in: "PRE"/)) | ||
|
||
|
||
test('Undefined key access throws', () => { | ||
const proxy = proxyFieldNames('PRE', { x: 'a' }) | ||
throws(() => proxy['missingKey'], | ||
/Accessing an undefined field: PRE_missingKey/) | ||
test('Undefined key access throws', () => { | ||
const proxy = proxyFieldNames('PRE', { x: 'a' }) | ||
throws(() => proxy['missingKey'], | ||
/Accessing an undefined field: PRE_missingKey/) | ||
}) | ||
}) | ||
|
||
|
Oops, something went wrong.