toml test, abstract string function with test
This commit is contained in:
parent
b10c132857
commit
e291dbc4a2
5 changed files with 58 additions and 15 deletions
14
dist/palette.toml
vendored
14
dist/palette.toml
vendored
|
@ -1,12 +1,12 @@
|
|||
name = verdigris
|
||||
version = 0.0.1
|
||||
license = GPL-3.0-only
|
||||
sourcecode = https://git.basking.monster/gaiety/verdigris
|
||||
name = "verdigris"
|
||||
version = "0.0.1"
|
||||
license = "GPL-3.0-only"
|
||||
sourcecode = "https://git.basking.monster/gaiety/verdigris"
|
||||
|
||||
[author]
|
||||
name = Gaiety
|
||||
email = ava+verdigris@gaiety.me
|
||||
url = https://gaiety.me
|
||||
name = "Gaiety"
|
||||
email = "ava+verdigris@gaiety.me"
|
||||
url = "https://gaiety.me"
|
||||
|
||||
[colors]
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import appRoot from 'app-root-path'
|
|||
import { rmFile, mkFilePath, appendToFile } from "../helpers/file"
|
||||
import colors from '../palette'
|
||||
import type color from '../helpers/color'
|
||||
import { toSnakeCase } from '../helpers/string'
|
||||
|
||||
const file = appRoot + '/dist/palette.toml'
|
||||
const appendToTOML = async (content: string) => await appendToFile(file, content)
|
||||
|
@ -28,10 +29,10 @@ export default async function(isVerbose = false): Promise<string> {
|
|||
}
|
||||
|
||||
function headerTOML(): string {
|
||||
return `name = ${name}
|
||||
version = ${version}
|
||||
license = ${license}
|
||||
sourcecode = ${url}
|
||||
return `name = "${name}"
|
||||
version = "${version}"
|
||||
license = "${license}"
|
||||
sourcecode = "${url}"
|
||||
`
|
||||
}
|
||||
|
||||
|
@ -40,9 +41,9 @@ function authorTOML(): string {
|
|||
|
||||
return `
|
||||
[author]
|
||||
name = ${name}
|
||||
email = ${email}
|
||||
url = ${url}
|
||||
name = "${name}"
|
||||
email = "${email}"
|
||||
url = "${url}"
|
||||
`
|
||||
}
|
||||
function colorHeaderTOML(): string {
|
||||
|
@ -54,7 +55,7 @@ function colorHeaderTOML(): string {
|
|||
function colorTOML(color: color): string {
|
||||
const { name, l, c, h } = color
|
||||
return `
|
||||
[colors.${name.replaceAll(' ', '_').toLowerCase()}]
|
||||
[colors.${toSnakeCase(name)}]
|
||||
name = "${name}"
|
||||
l = ${l}
|
||||
c = ${c}
|
||||
|
|
3
src/helpers/string.ts
Normal file
3
src/helpers/string.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function toSnakeCase(str: string): string {
|
||||
return str.replaceAll(' ', '_').toLowerCase()
|
||||
}
|
30
tests/dist/toml.test.ts
vendored
Normal file
30
tests/dist/toml.test.ts
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { name, version, license, url, author } from '../../package.json'
|
||||
import { expect, test } from 'bun:test'
|
||||
import data from '../../dist/palette.toml'
|
||||
import colors from '../../src/palette'
|
||||
import { toSnakeCase } from '../../src/helpers/string'
|
||||
|
||||
test('has header info', () => {
|
||||
expect(data.name).toBe(name)
|
||||
expect(data.version).toBe(version)
|
||||
expect(data.license).toBe(license)
|
||||
expect(data.sourcecode).toBe(url)
|
||||
|
||||
expect(data.author.name).toBe(author.name)
|
||||
expect(data.author.email).toBe(author.email)
|
||||
expect(data.author.url).toBe(author.url)
|
||||
})
|
||||
|
||||
test('has expected colors', () => {
|
||||
colors.forEach(color => {
|
||||
const { name, l, c, h } = color
|
||||
const dataColor = data.colors[toSnakeCase(name)]
|
||||
|
||||
expect(dataColor.name).toBe(name)
|
||||
expect(dataColor.l).toBe(l)
|
||||
expect(dataColor.c).toBe(c)
|
||||
expect(dataColor.h).toBe(h)
|
||||
expect(dataColor.hex).toBe(color.toHex())
|
||||
})
|
||||
})
|
||||
|
9
tests/helpers/string.test.ts
Normal file
9
tests/helpers/string.test.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { expect, test } from 'bun:test'
|
||||
import { toSnakeCase } from '../../src/helpers/string'
|
||||
|
||||
test('can convert a string to snake case', () => {
|
||||
expect(
|
||||
toSnakeCase('Very Cool Beans')
|
||||
).toBe('very_cool_beans')
|
||||
})
|
||||
|
Loading…
Add table
Reference in a new issue