aboutsummaryrefslogtreecommitdiff
path: root/test/int_test.gleam
blob: d5f0f5812a49f88f990d9a12b7b17b937589586c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import expect
import int

pub fn to_string() {
  123
  |> int:to_string
  |> expect:equal(_, "123")

  -123
  |> int:to_string
  |> expect:equal(_, "-123")

  0123
  |> int:to_string
  |> expect:equal(_, "123")
}

pub fn parse() {
  "123"
  |> int:parse
  |> expect:equal(_, Ok(123))

  "-123"
  |> int:parse
  |> expect:equal(_, Ok(-123))

  "0123"
  |> int:parse
  |> expect:equal(_, Ok(123))

  ""
  |> int:parse
  |> expect:is_error

  "what"
  |> int:parse
  |> expect:is_error

  "1.23"
  |> int:parse
  |> expect:is_error
}

pub fn to_base_string() {
  100
  |> int:to_base_string(_, 16)
  |> expect:equal(_, "64")

  -100
  |> int:to_base_string(_, 16)
  |> expect:equal(_, "-64")
}