-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfmt.jl
More file actions
60 lines (47 loc) · 1.71 KB
/
Copy pathfmt.jl
File metadata and controls
60 lines (47 loc) · 1.71 KB
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
# some basic functionality testing
x = 1234.56789
@test fmt(x) == "1234.567890"
@test fmt(x;prec=2) == "1234.57"
@test fmt(x,10,3) == " 1234.568"
@test fmt(x,10,3,:left) == "1234.568 "
@test fmt(x,10,3,:ljust) == "1234.568 "
@test fmt(x,10,3,:right) == " 1234.568"
@test fmt(x,10,3,:lrjust) == " 1234.568"
@test fmt(x,10,3,:zpad) == "001234.568"
@test fmt(x,10,3,:zeropad) == "001234.568"
@test fmt(x,:commas) == "1,234.567890"
@test fmt(x,10,3,:left,:commas) == "1,234.568 "
@test fmt(x,:ipre) == "1234.567890"
@test fmt(x,12) == " 1234.567890"
i = 1234567
@test fmt(i) == "1234567"
@test fmt(i,:commas) == "1,234,567"
@test fmt(2 - 3im, 10) == " 2 - 3im"
@test fmt(pi - 3im, 15, 2) == " 3.14 - 3.00im"
@test fmt(3//4, 10) == " 3//4"
@test fmt(1//2 + 6//2 * im, 15) == " 1//2 + 3//1*im"
fmt_default!(Rational, 'f', prec = 2)
fmt_default!(Format.ComplexRational, 'f', prec = 2)
@test fmt(3//4, 10, 2) == " 0.75"
@test fmt(3//4, 10, 1) == " 0.8"
@test fmt(1//2 + 6//2 * im, 23) == " 0.500000 + 3.000000im"
@test fmt(1//2 + 6//2 * im, 15, 2) == " 0.50 + 3.00im"
fmt_default!(Int, :commas, width = 12)
@test fmt(i) == " 1,234,567"
@test fmt(x) == "1234.567890" # default hasn't changed
fmt_default!(:commas)
@test fmt(i) == " 1,234,567"
@test fmt(x) == "1,234.567890" # width hasn't changed, but added commas
fmt_default!(Int) # resets Integer defaults
@test fmt(i) == "1234567"
@test fmt(i,:commas) == "1,234,567"
reset!(Int)
fmt_default!(UInt16, 'd', :commas)
@test fmt(0xffff) == "65,535"
fmt_default!(UInt32, UInt16, width=20)
@test fmt(0xfffff) == " 1,048,575"
v = pi
@test fmt(v) == "π"
@test fmt(v; width=10) == " π"
v = MathConstants.eulergamma
@test fmt(v, 10, 2) == " γ"