Skip to content

Commit a0b3a78

Browse files
authored
Merge branch 'master' into fix-tree-shaking
2 parents 759b548 + ab6c728 commit a0b3a78

File tree

5 files changed

+90
-106
lines changed

5 files changed

+90
-106
lines changed

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ jobs:
1414
cache: 'yarn'
1515
- run: yarn install --frozen-lockfile
1616
- name: Check formatting
17-
run: yarn rescript format -check
17+
run: yarn check
1818
- name: Run the tests 👀
1919
run: yarn test

__tests__/Tinycolor_tests.res

Lines changed: 64 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ open Jest
22
open Expect
33
open! Expect.Operators
44

5-
open Belt
6-
75
describe("making tinycolor", () => {
86
test("fromString() returns valid from string", () => {
97
let black = TinyColor.makeFromString("black")
@@ -75,9 +73,7 @@ describe("making tinycolor", () => {
7573
let input: TinyColor.rgbaRatio = {r: 0.1, g: 0.5, b: 0.7, a: 0.7}
7674
let a = TinyColor.makeFromRgbaRatio(input)
7775

78-
expect(Option.map(a, TinyColor.getOriginalInput))->toEqual(
79-
Some(TinyColor.rgbaRatioToJs(input)),
80-
)
76+
expect(Option.map(a, TinyColor.getOriginalInput))->toEqual(Some(TinyColor.rgbaRatioToJs(input)))
8177
})
8278

8379
test("makeFromHsl() returns valid", () => {
@@ -112,9 +108,7 @@ describe("making tinycolor", () => {
112108
let input: TinyColor.hslaRatio = {h: 0.1, s: 0.5, l: 0.7, a: 0.7}
113109
let a = TinyColor.makeFromHslaRatio(input)
114110

115-
expect(Option.map(a, TinyColor.getOriginalInput))->toEqual(
116-
Some(TinyColor.hslaRatioToJs(input)),
117-
)
111+
expect(Option.map(a, TinyColor.getOriginalInput))->toEqual(Some(TinyColor.hslaRatioToJs(input)))
118112
})
119113

120114
test("makeFromHsv() returns valid", () => {
@@ -149,9 +143,7 @@ describe("making tinycolor", () => {
149143
let input: TinyColor.hsvaRatio = {h: 0.1, s: 0.5, v: 0.7, a: 0.7}
150144
let a = TinyColor.makeFromHsvaRatio(input)
151145

152-
expect(Option.map(a, TinyColor.getOriginalInput))->toEqual(
153-
Some(TinyColor.hsvaRatioToJs(input)),
154-
)
146+
expect(Option.map(a, TinyColor.getOriginalInput))->toEqual(Some(TinyColor.hsvaRatioToJs(input)))
155147
})
156148
test("makeFromCmyk() returns valid", () => {
157149
let a = TinyColor.makeFromCmyk({c: 0, m: 100, y: 100, k: 0})
@@ -217,9 +209,7 @@ describe("onBackground()", () => {
217209
switch (blue, red) {
218210
| (Some(blue), Some(red)) =>
219211
let bluePartlyTransparent = TinyColor.setAlpha(0.5, blue)
220-
expect(
221-
TinyColor.onBackground(bluePartlyTransparent, red)->TinyColor.toHexString,
222-
) == "#800080"
212+
expect(TinyColor.onBackground(bluePartlyTransparent, red)->TinyColor.toHexString) == "#800080"
223213
| _ => expect(true) == false
224214
}
225215
)
@@ -354,68 +344,70 @@ describe("color modification tests", () => {
354344

355345
test("lighten(int, t)", () =>
356346
optionMapTwo(red, c => TinyColor.lighten(~value=10, c), TinyColor.toHexString)
357-
->expect
358-
->toEqual(Some("#ff3333"))
347+
->expect
348+
->toEqual(Some("#ff3333"))
359349
)
360350

361351
test("lighten(int, t) does not change original instance", () =>
362352
optionMapTwo(red, c => TinyColor.lighten(~value=10, c), TinyColor.toHex8String)
363-
->expect
364-
->not_
365-
->toEqual(Option.map(red, TinyColor.toHex8String))
353+
->expect
354+
->not_
355+
->toEqual(Option.map(red, TinyColor.toHex8String))
366356
)
367357

368358
test("brighten(int, t)", () =>
369359
optionMapTwo(red, c => TinyColor.brighten(~value=10, c), TinyColor.toHexString)
370-
->expect
371-
->toEqual(Some("#ff1919"))
360+
->expect
361+
->toEqual(Some("#ff1919"))
372362
)
373363

374364
test("brighten(int, t) dose not change original instance", () =>
375365
optionMapTwo(red, c => TinyColor.brighten(~value=10, c), TinyColor.toString)
376-
->expect
377-
->not_
378-
->toEqual(Option.map(red, TinyColor.toString))
366+
->expect
367+
->not_
368+
->toEqual(Option.map(red, TinyColor.toString))
379369
)
380370

381371
test("darken(int, t)", () =>
382372
optionMapTwo(red, c => TinyColor.darken(~value=10, c), TinyColor.toHexString)
383-
->expect
384-
->toEqual(Some("#cc0000"))
373+
->expect
374+
->toEqual(Some("#cc0000"))
385375
)
386376

387377
test("tint(int, t)", () =>
388378
optionMapTwo(red, c => TinyColor.tint(~value=10, c), TinyColor.toHexString)
389-
->expect
390-
->toEqual(Some("#ff1a1a"))
379+
->expect
380+
->toEqual(Some("#ff1a1a"))
391381
)
392382

393383
test("shade(int, t)", () =>
394384
optionMapTwo(red, c => TinyColor.shade(~value=10, c), TinyColor.toHexString)
395-
->expect
396-
->toEqual(Some("#e60000"))
385+
->expect
386+
->toEqual(Some("#e60000"))
397387
)
398388

399389
test("desaturate(int, t)", () =>
400390
optionMapTwo(red, c => TinyColor.desaturate(~value=10, c), TinyColor.toHexString)
401-
->expect
402-
->toEqual(Some("#f20d0d"))
391+
->expect
392+
->toEqual(Some("#f20d0d"))
403393
)
404394

405395
test("saturate(int, t)", () =>
406396
optionMapTwo(red, c => TinyColor.saturate(~value=10, c), TinyColor.toHexString)
407-
->expect
408-
->toEqual(Some("#ff0000"))
397+
->expect
398+
->toEqual(Some("#ff0000"))
409399
)
410400

411401
test("spin(int, t)", () =>
412-
Option.map(red, c => TinyColor.spin(~value=180, c))->Option.map(TinyColor.toHex8String)
413-
->expect === Some("#00ffffff")
402+
Option.map(red, c => TinyColor.spin(~value=180, c))
403+
->Option.map(TinyColor.toHex8String)
404+
->expect === Some("#00ffffff")
414405
)
415406

416407
test("spin(int, t) with value 360 does not change", () =>
417-
Option.map(red, c => TinyColor.spin(~value=360, c))->Option.map(TinyColor.toHex8String)
418-
->expect === Option.map(red, TinyColor.toHex8String)
408+
Option.map(red, c => TinyColor.spin(~value=360, c))
409+
->Option.map(TinyColor.toHex8String)
410+
->expect === Option.map(red, TinyColor.toHex8String)
419411
)
420412

421413
test("mix(int, t)", () => {
@@ -424,66 +416,68 @@ describe("color modification tests", () => {
424416

425417
switch (color1, color2) {
426418
| (Some(c1), Some(c2)) =>
427-
TinyColor.mix(~value=50, c1, c2)->Option.map(TinyColor.toHexString)
428-
->expect
429-
->toEqual(Some("#808080"))
419+
TinyColor.mix(~value=50, c1, c2)
420+
->Option.map(TinyColor.toHexString)
421+
->expect
422+
->toEqual(Some("#808080"))
430423
| _ => expect(false) === true
431424
}
432425
})
433426

434427
test("greyscale(t)", () =>
435-
Option.map(red, TinyColor.greyscale)->Option.map(TinyColor.toHex8String)
436-
->expect === Some("#808080ff")
428+
Option.map(red, TinyColor.greyscale)
429+
->Option.map(TinyColor.toHex8String)
430+
->expect === Some("#808080ff")
437431
)
438432
})
439433

440434
describe("color combinations", () => {
441435
let mapAndReturnHexArray = (color, fn) =>
442-
Option.map(color, fn)->Option.getWithDefault([])->Array.map(TinyColor.toHexString)
436+
Option.map(color, fn)->Option.getOr([])->Belt.Array.map(TinyColor.toHexString)
443437

444438
test("analogous()", () =>
445439
TinyColor.makeFromString("#f00")
446-
->Option.getExn
440+
->Option.getOrThrow
447441
->TinyColor.analogous()
448442
->Array.map(TinyColor.toHexString)
449-
->expect
450-
->toEqual(["#ff0000", "#ff0066", "#ff0033", "#ff0000", "#ff3300", "#ff6600"])
443+
->expect
444+
->toEqual(["#ff0000", "#ff0066", "#ff0033", "#ff0000", "#ff3300", "#ff6600"])
451445
)
452446

453447
test("monochromatic()", () =>
454448
TinyColor.makeFromString("#f00")
455-
->Option.getExn
449+
->Option.getOrThrow
456450
->TinyColor.monochromatic()
457451
->Array.map(TinyColor.toHexString)
458-
->expect
459-
->toEqual(["#ff0000", "#2a0000", "#550000", "#800000", "#aa0000", "#d40000"])
452+
->expect
453+
->toEqual(["#ff0000", "#2a0000", "#550000", "#800000", "#aa0000", "#d40000"])
460454
)
461455

462456
test("splitcomplement()", () =>
463457
mapAndReturnHexArray(TinyColor.makeFromString("#f00"), TinyColor.splitcomplement)
464-
->expect
465-
->toEqual(["#ff0000", "#ccff00", "#0066ff"])
458+
->expect
459+
->toEqual(["#ff0000", "#ccff00", "#0066ff"])
466460
)
467461

468462
test("triad()", () =>
469463
mapAndReturnHexArray(TinyColor.makeFromString("#f00"), TinyColor.triad)
470-
->expect
471-
->toEqual(["#ff0000", "#00ff00", "#0000ff"])
464+
->expect
465+
->toEqual(["#ff0000", "#00ff00", "#0000ff"])
472466
)
473467

474468
test("tetrad()", () =>
475469
mapAndReturnHexArray(TinyColor.makeFromString("#f00"), TinyColor.tetrad)
476-
->expect
477-
->toEqual(["#ff0000", "#80ff00", "#00ffff", "#7f00ff"])
470+
->expect
471+
->toEqual(["#ff0000", "#80ff00", "#00ffff", "#7f00ff"])
478472
)
479473

480474
test("polyad()", () =>
481475
TinyColor.makeFromString("#f00")
482-
->Option.getExn
476+
->Option.getOrThrow
483477
->TinyColor.polyad(~n=4, ())
484478
->Array.map(TinyColor.toHexString)
485-
->expect
486-
->toEqual(["#ff0000", "#80ff00", "#00ffff", "#7f00ff"])
479+
->expect
480+
->toEqual(["#ff0000", "#80ff00", "#00ffff", "#7f00ff"])
487481
)
488482

489483
test("complement()", () => {
@@ -500,14 +494,14 @@ describe("color utils", () => {
500494
let a = TinyColor.makeFromString("red")
501495
let b = TinyColor.makeFromRgb({r: 255, g: 0, b: 0})
502496

503-
expect(Option.eq(a, b, TinyColor.equals)) === true
497+
expect(Option.equal(a, b, TinyColor.equals)) === true
504498
})
505499

506500
test("equals() returns false for unequal colors", () => {
507501
let a = TinyColor.makeFromString("red")
508502
let b = TinyColor.makeFromString("blue")
509503

510-
expect(Option.eq(a, b, TinyColor.equals)) === false
504+
expect(Option.equal(a, b, TinyColor.equals)) === false
511505
})
512506

513507
test("random()", () => {
@@ -525,31 +519,31 @@ describe("color utils", () => {
525519

526520
test("randomMultiple() returns empty array for count=0", () => {
527521
let a = TinyColor.randomMultiple(~count=0, ())
528-
expect(Array.length(a))->toBe(0)
522+
expect(Belt.Array.length(a))->toBe(0)
529523
})
530524

531525
test("randomMultiple() returns single element in array", () => {
532526
let a = TinyColor.randomMultiple(~count=1, ())
533527

534-
expect(Array.length(a))->toBe(1)
528+
expect(Belt.Array.length(a))->toBe(1)
535529
})
536530

537531
test("randomMultiple() returns many elements", () => {
538532
let a = TinyColor.randomMultiple(~count=15, ())
539533

540-
expect(Array.length(a))->toBe(15)
534+
expect(Belt.Array.length(a))->toBe(15)
541535
})
542536

543537
test("randomMultiple() returns all different colors", () => {
544538
let a = TinyColor.randomMultiple(~count=4, ())
545539

546540
expect(
547-
!TinyColor.equals(Array.getExn(a, 0), Array.getExn(a, 1)) &&
548-
(!TinyColor.equals(Array.getExn(a, 0), Array.getExn(a, 2)) &&
549-
(!TinyColor.equals(Array.getExn(a, 0), Array.getExn(a, 3)) &&
550-
(!TinyColor.equals(Array.getExn(a, 1), Array.getExn(a, 2)) &&
551-
(!TinyColor.equals(Array.getExn(a, 1), Array.getExn(a, 3)) &&
552-
!TinyColor.equals(Array.getExn(a, 2), Array.getExn(a, 3)))))),
541+
!TinyColor.equals(Belt.Array.getExn(a, 0), Belt.Array.getExn(a, 1)) &&
542+
(!TinyColor.equals(Belt.Array.getExn(a, 0), Belt.Array.getExn(a, 2)) &&
543+
(!TinyColor.equals(Belt.Array.getExn(a, 0), Belt.Array.getExn(a, 3)) &&
544+
(!TinyColor.equals(Belt.Array.getExn(a, 1), Belt.Array.getExn(a, 2)) &&
545+
(!TinyColor.equals(Belt.Array.getExn(a, 1), Belt.Array.getExn(a, 3)) &&
546+
!TinyColor.equals(Belt.Array.getExn(a, 2), Belt.Array.getExn(a, 3)))))),
553547
) === true
554548
})
555549

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"name": "rescript-tinycolor",
3-
"version": "5.0.0",
3+
"version": "5.1.0",
44
"scripts": {
55
"build": "rescript build",
66
"start": "rescript build -w",
77
"clean": "rescript clean",
8+
"check": "rescript format --check",
9+
"format": "rescript format",
810
"pretest": "npm run build",
911
"test": "jest"
1012
},

0 commit comments

Comments
 (0)