import { assertEquals, test } from "Test"

import { Left, Right } from "Either"
import { integer, list, parse, string, float } from "./Parse"



test("parse - success", () => assertEquals(parse(string, `"Json string"`), Right("Json string")))
test("parse - error", () => assertEquals(parse(string, `3`), Left("Error parsing string")))

test(
  "list  - success",
  () => assertEquals(
    parse(list(string), `["one string", "two strings"]`),
    Right(["one string", "two strings",])
  )
)

test("list  - error", () => assertEquals(parse(list(string), `1`), Left("Error parsing list")))

test("float - good", () => assertEquals(parse(float, `1.3`), Right(1.3)))

test("integer - negative", () => assertEquals(parse(integer, `-1`), Right(-1)))

test("float - negative", () => assertEquals(parse(float, `-1.0`), Right(-1_f)))

test("float - without decimal", () => assertEquals(parse(float, `1`), Right(1)))

test("float - negative without decimal", () => assertEquals(parse(float, `-1`), Right(-1)))
