Skip to content

Commit d053837

Browse files
giacomocavalierilpil
authored andcommitted
use assert in examples
1 parent ae49a41 commit d053837

17 files changed

Lines changed: 709 additions & 1112 deletions

src/gleam/bit_array.gleam

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ pub fn pad_to_bytes(x: BitArray) -> BitArray
3333
/// ## Examples
3434
///
3535
/// ```gleam
36-
/// append(to: from_string("butter"), suffix: from_string("fly"))
37-
/// // -> from_string("butterfly")
36+
/// assert append(to: from_string("butter"), suffix: from_string("fly"))
37+
/// == from_string("butterfly")
3838
/// ```
3939
///
4040
pub fn append(to first: BitArray, suffix second: BitArray) -> BitArray {
@@ -100,8 +100,8 @@ fn unsafe_to_string(a: BitArray) -> String
100100
/// ## Examples
101101
///
102102
/// ```gleam
103-
/// concat([from_string("butter"), from_string("fly")])
104-
/// // -> from_string("butterfly")
103+
/// assert concat([from_string("butter"), from_string("fly")])
104+
/// == from_string("butterfly")
105105
/// ```
106106
///
107107
@external(erlang, "gleam_stdlib", "bit_array_concat")
@@ -177,11 +177,11 @@ pub fn base16_decode(input: String) -> Result(BitArray, Nil)
177177
/// ## Examples
178178
///
179179
/// ```gleam
180-
/// inspect(<<0, 20, 0x20, 255>>)
181-
/// // -> "<<0, 20, 32, 255>>"
180+
/// assert inspect(<<0, 20, 0x20, 255>>) == "<<0, 20, 32, 255>>"
181+
/// ```
182182
///
183-
/// inspect(<<100, 5:3>>)
184-
/// // -> "<<100, 5:size(3)>>"
183+
/// ```gleam
184+
/// assert inspect(<<100, 5:3>>) == "<<100, 5:size(3)>>"
185185
/// ```
186186
///
187187
pub fn inspect(input: BitArray) -> String {
@@ -219,14 +219,15 @@ fn inspect_loop(input: BitArray, accumulator: String) -> String {
219219
/// ## Examples
220220
///
221221
/// ```gleam
222-
/// compare(<<1>>, <<2>>)
223-
/// // -> Lt
222+
/// assert compare(<<1>>, <<2>>) == Lt
223+
/// ```
224224
///
225-
/// compare(<<"AB":utf8>>, <<"AA":utf8>>)
226-
/// // -> Gt
225+
/// ```gleam
226+
/// assert compare(<<"AB":utf8>>, <<"AA":utf8>>) == Gt
227+
/// ```
227228
///
228-
/// compare(<<1, 2:size(2)>>, with: <<1, 2:size(2)>>)
229-
/// // -> Eq
229+
/// ```gleam
230+
/// assert compare(<<1, 2:size(2)>>, with: <<1, 2:size(2)>>) == Eq
230231
/// ```
231232
///
232233
pub fn compare(a: BitArray, with b: BitArray) -> order.Order {
@@ -265,8 +266,7 @@ fn bit_array_to_int_and_size(a: BitArray) -> #(Int, Int)
265266
/// ## Examples
266267
///
267268
/// ```gleam
268-
/// starts_with(<<1, 2, 3, 4>>, <<1, 2>>)
269-
/// // -> True
269+
/// assert starts_with(<<1, 2, 3, 4>>, <<1, 2>>)
270270
/// ```
271271
///
272272
@external(javascript, "../gleam_stdlib.mjs", "bit_array_starts_with")

src/gleam/bool.gleam

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
/// ## Examples
1515
///
1616
/// ```gleam
17-
/// and(True, True)
18-
/// // -> True
17+
/// assert and(True, True)
1918
/// ```
2019
///
2120
/// ```gleam
22-
/// and(False, True)
23-
/// // -> False
21+
/// assert !and(False, True)
2422
/// ```
2523
///
2624
/// ```gleam
27-
/// False |> and(True)
28-
/// // -> False
25+
/// assert !and(False, True)
26+
/// ```
27+
///
28+
/// ```gleam
29+
/// assert !and(False, False)
2930
/// ```
3031
///
3132
pub fn and(a: Bool, b: Bool) -> Bool {
@@ -40,18 +41,19 @@ pub fn and(a: Bool, b: Bool) -> Bool {
4041
/// ## Examples
4142
///
4243
/// ```gleam
43-
/// or(True, True)
44-
/// // -> True
44+
/// assert or(True, True)
45+
/// ```
46+
///
47+
/// ```gleam
48+
/// assert or(False, True)
4549
/// ```
4650
///
4751
/// ```gleam
48-
/// or(False, True)
49-
/// // -> True
52+
/// assert or(False, True)
5053
/// ```
5154
///
5255
/// ```gleam
53-
/// False |> or(True)
54-
/// // -> True
56+
/// assert !or(False, False)
5557
/// ```
5658
///
5759
pub fn or(a: Bool, b: Bool) -> Bool {
@@ -65,13 +67,11 @@ pub fn or(a: Bool, b: Bool) -> Bool {
6567
/// ## Examples
6668
///
6769
/// ```gleam
68-
/// negate(True)
69-
/// // -> False
70+
/// assert !negate(True)
7071
/// ```
7172
///
7273
/// ```gleam
73-
/// negate(False)
74-
/// // -> True
74+
/// assert negate(False)
7575
/// ```
7676
///
7777
pub fn negate(bool: Bool) -> Bool {
@@ -83,23 +83,19 @@ pub fn negate(bool: Bool) -> Bool {
8383
/// ## Examples
8484
///
8585
/// ```gleam
86-
/// nor(False, False)
87-
/// // -> True
86+
/// assert nor(False, False)
8887
/// ```
8988
///
9089
/// ```gleam
91-
/// nor(False, True)
92-
/// // -> False
90+
/// assert !nor(False, True)
9391
/// ```
9492
///
9593
/// ```gleam
96-
/// nor(True, False)
97-
/// // -> False
94+
/// assert !nor(True, False)
9895
/// ```
9996
///
10097
/// ```gleam
101-
/// nor(True, True)
102-
/// // -> False
98+
/// assert !nor(True, True)
10399
/// ```
104100
///
105101
pub fn nor(a: Bool, b: Bool) -> Bool {
@@ -111,23 +107,19 @@ pub fn nor(a: Bool, b: Bool) -> Bool {
111107
/// ## Examples
112108
///
113109
/// ```gleam
114-
/// nand(False, False)
115-
/// // -> True
110+
/// assert nand(False, False)
116111
/// ```
117112
///
118113
/// ```gleam
119-
/// nand(False, True)
120-
/// // -> True
114+
/// assert nand(False, True)
121115
/// ```
122116
///
123117
/// ```gleam
124-
/// nand(True, False)
125-
/// // -> True
118+
/// assert nand(True, False)
126119
/// ```
127120
///
128121
/// ```gleam
129-
/// nand(True, True)
130-
/// // -> False
122+
/// assert !nand(True, True)
131123
/// ```
132124
///
133125
pub fn nand(a: Bool, b: Bool) -> Bool {
@@ -139,23 +131,19 @@ pub fn nand(a: Bool, b: Bool) -> Bool {
139131
/// ## Examples
140132
///
141133
/// ```gleam
142-
/// exclusive_or(False, False)
143-
/// // -> False
134+
/// assert !exclusive_or(False, False)
144135
/// ```
145136
///
146137
/// ```gleam
147-
/// exclusive_or(False, True)
148-
/// // -> True
138+
/// assert exclusive_or(False, True)
149139
/// ```
150140
///
151141
/// ```gleam
152-
/// exclusive_or(True, False)
153-
/// // -> True
142+
/// assert exclusive_or(True, False)
154143
/// ```
155144
///
156145
/// ```gleam
157-
/// exclusive_or(True, True)
158-
/// // -> False
146+
/// assert !exclusive_or(True, True)
159147
/// ```
160148
///
161149
pub fn exclusive_or(a: Bool, b: Bool) -> Bool {
@@ -167,23 +155,19 @@ pub fn exclusive_or(a: Bool, b: Bool) -> Bool {
167155
/// ## Examples
168156
///
169157
/// ```gleam
170-
/// exclusive_nor(False, False)
171-
/// // -> True
158+
/// assert exclusive_nor(False, False)
172159
/// ```
173160
///
174161
/// ```gleam
175-
/// exclusive_nor(False, True)
176-
/// // -> False
162+
/// assert !exclusive_nor(False, True)
177163
/// ```
178164
///
179165
/// ```gleam
180-
/// exclusive_nor(True, False)
181-
/// // -> False
166+
/// assert !exclusive_nor(True, False)
182167
/// ```
183168
///
184169
/// ```gleam
185-
/// exclusive_nor(True, True)
186-
/// // -> True
170+
/// assert exclusive_nor(True, True)
187171
/// ```
188172
///
189173
pub fn exclusive_nor(a: Bool, b: Bool) -> Bool {
@@ -195,13 +179,11 @@ pub fn exclusive_nor(a: Bool, b: Bool) -> Bool {
195179
/// ## Examples
196180
///
197181
/// ```gleam
198-
/// to_string(True)
199-
/// // -> "True"
182+
/// assert to_string(True) == "True"
200183
/// ```
201184
///
202185
/// ```gleam
203-
/// to_string(False)
204-
/// // -> "False"
186+
/// assert to_string(False) == "False"
205187
/// ```
206188
///
207189
pub fn to_string(bool: Bool) -> String {

0 commit comments

Comments
 (0)