-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathexample_test.go
70 lines (64 loc) · 1.28 KB
/
example_test.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package humanize
import (
"log"
time "github.com/vadv/gopher-lua-libs/time"
lua "github.com/yuin/gopher-lua"
)
// humanize.ibytes(number)
func ExampleIBytes() {
state := lua.NewState()
Preload(state)
source := `
local humanize = require("humanize")
print(humanize.ibytes(1395864371))
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// 1.3 GiB
}
// humanize.parse_bytes(string)
func ExampleParseBytes() {
state := lua.NewState()
Preload(state)
source := `
local humanize = require("humanize")
print(humanize.parse_bytes("1.3GiB"))
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// 1395864371
}
// humanize.time(number)
func ExampleTime() {
state := lua.NewState()
Preload(state)
time.Preload(state)
source := `
local humanize = require("humanize")
local time = require("time")
print(humanize.time(time.unix() - 61))
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// 1 minute ago
}
// humanize.si(input, unit)
func ExampleSI() {
state := lua.NewState()
Preload(state)
source := `
local humanize = require("humanize")
print(humanize.si(0.212121, "m"))
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// 212.121 mm
}