@@ -17,94 +17,93 @@ defmodule Inspect.AlgebraTest do
17
17
18
18
def factor ( doc , w ) , do: format ( w , 0 , [ { 0 , :flat , group ( doc ) } ] )
19
19
20
- test : empty do
20
+ test " empty doc" do
21
21
# Consistence with definitions
22
22
assert empty == :doc_nil
23
+
23
24
# Consistence of corresponding sdoc
24
25
assert factor ( empty , 80 ) == [ ]
26
+
25
27
# Consistent formatting
26
28
assert pretty ( empty , 80 ) == ""
27
29
end
28
30
29
- test : break do
31
+ test " break doc" do
30
32
# Consistence with definitions
31
- ## Normal case
32
33
assert break ( "break" ) == { :doc_break , "break" }
33
- ## Degeneracy
34
34
assert break ( "" ) == { :doc_break , "" }
35
- ## ong argument type
35
+
36
+ # Wrong argument type
36
37
assert_raise FunctionClauseError , fn -> break ( 42 ) end
38
+
37
39
# Consistence of corresponding sdoc
38
40
assert factor ( break ( "_" ) , 80 ) == [ "_" ]
41
+
39
42
# Consistent formatting
40
43
assert pretty ( break ( "_" ) , 80 ) == "_"
41
44
end
42
45
43
- test : glue do
46
+ test " glue doc" do
44
47
# Consistence with definitions
45
48
assert glue ( "a" , "->" , "b" ) == { :doc_cons ,
46
49
"a" , { :doc_cons , { :doc_break , "->" } , "b" }
47
50
}
48
51
assert glue ( "a" , "b" ) == glue ( "a" , " " , "b" )
49
52
50
- ## Wrong argument type
53
+ # Wrong argument type
51
54
assert_raise FunctionClauseError , fn -> glue ( "a" , 42 , "b" ) end
52
55
end
53
56
54
- test : text do
55
- # Consistence of corresponding docfactor
57
+ test " text doc" do
58
+ # Consistence of corresponding sdoc
56
59
assert factor ( "_" , 80 ) == [ "_" ]
60
+
57
61
# Consistent formatting
58
62
assert pretty ( "_" , 80 ) == "_"
59
63
end
60
64
61
- test : space do
65
+ test " space doc" do
62
66
# Consistency with definitions
63
67
assert space ( "a" , "b" ) == { :doc_cons ,
64
68
"a" , { :doc_cons , " " , "b" }
65
69
}
66
70
end
67
71
68
- test : nest do
72
+ test " nest doc" do
69
73
# Consistence with definitions
70
- ## Normal case
71
74
assert nest ( empty , 1 ) == { :doc_nest , 1 , empty }
72
- ## Degeneracy
73
75
assert nest ( empty , 0 ) == :doc_nil
74
- ## ong argument type
76
+
77
+ # Wrong argument type
75
78
assert_raise FunctionClauseError , fn -> nest ( "foo" , empty ) end
76
79
77
- a1 = fn -> nest ( "a" , 1 ) end
78
- alb1 = fn -> nest ( glue ( "a" , "b" ) , 1 ) end
79
80
# Consistence of corresponding sdoc
80
- ## Trivial case
81
- assert factor ( a1 . ( ) , 80 ) == [ "a" ]
82
- ## Correctly indenting line forcing linebreak
83
- assert format ( 2 , 0 , [ { 0 , :break , alb1 . ( ) } ] ) == [ "a" , "\n " , " " , "b" ]
81
+ assert factor ( nest ( "a" , 1 ) , 80 ) == [ "a" ]
82
+ assert format ( 2 , 0 , [ { 0 , :break , nest ( glue ( "a" , "b" ) , 1 ) } ] ) == [ "a" , "\n " , "b" ]
84
83
85
84
# Consistent formatting
86
- ## Trivial case
87
- assert pretty ( a1 . ( ) , 80 ) == "a"
88
- ## Correctly indenting line
89
- assert render ( format 2 , 0 , [ { 0 , :break , alb1 . ( ) } ] ) == "a\n b"
85
+ assert pretty ( nest ( "a" , 1 ) , 80 ) == "a"
86
+ assert render ( format 2 , 0 , [ { 0 , :break , nest ( glue ( "a" , "b" ) , 1 ) } ] ) == "a\n b"
90
87
end
91
88
92
- test :infinity do
93
- # w = :infinity should disable pretty printer
94
- s = String . duplicate "x" , 50
95
- g = ";"
96
- big_document = group ( glue ( s , g , s ) |> glue ( g , s ) |> glue ( g , s ) |> glue ( g , s ) )
89
+ test "line doc" do
90
+ # Consistency with definitions
91
+ assert line ( "a" , "b" ) ==
92
+ { :doc_cons , "a" , { :doc_cons , :doc_line , "b" } }
93
+
94
+ # Consistence of corresponding sdoc
95
+ assert factor ( line ( "a" , "b" ) , 1 ) == [ "a" , "\n " , "b" ]
96
+ assert factor ( line ( "a" , "b" ) , 9 ) == [ "a" , "\n " , "b" ]
97
97
98
- assert pretty ( big_document , :infinity ) == s <> g <> s <> g <> s <> g <> s <> g <> s
98
+ # Consistent formatting
99
+ assert pretty ( line ( glue ( "aaa" , "bbb" ) , glue ( "ccc" , "ddd" ) ) , 10 ) ==
100
+ "aaa bbb\n ccc ddd"
99
101
end
100
102
101
- test : group do
103
+ test " group doc" do
102
104
# Consistency with definitions
103
- ## Normal case
104
105
assert group ( glue ( "a" , "b" ) ) ==
105
106
{ :doc_group , { :doc_cons , "a" , concat ( break , "b" ) } }
106
-
107
- ## Degeneracy
108
107
assert group ( empty ) == { :doc_group , empty }
109
108
110
109
# Consistence of corresponding sdoc
@@ -115,4 +114,12 @@ defmodule Inspect.AlgebraTest do
115
114
assert pretty ( helloabcd , 5 ) == "hello\n a b\n cd"
116
115
assert pretty ( helloabcd , 80 ) == "hello a b cd"
117
116
end
117
+
118
+ test "formatting with infinity" do
119
+ s = String . duplicate "x" , 50
120
+ g = ";"
121
+ doc = group ( glue ( s , g , s ) |> glue ( g , s ) |> glue ( g , s ) |> glue ( g , s ) )
122
+
123
+ assert pretty ( doc , :infinity ) == s <> g <> s <> g <> s <> g <> s <> g <> s
124
+ end
118
125
end
0 commit comments