Skip to content

Commit 8bb6709

Browse files
Fix trailing whitespace in 4 files
Pre-commit automatically removed trailing spaces. Co-Authored-By: Warp <agent@warp.dev>
1 parent c7ee266 commit 8bb6709

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

fixtures/edge_cases.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ double = "quoted value"
2323
mixed = 'single" and "double' quotes
2424

2525
[EmptyValues]
26-
empty_explicit =
26+
empty_explicit =
2727
empty_implicit =
2828

2929
[UnicodeValues]

src/ini/writer.mojo

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ from collections import Dict
3030

3131
struct Writer:
3232
"""INI writer for serialising Dict structures to INI format.
33-
33+
3434
The writer builds INI output incrementally in a string buffer,
3535
handling proper formatting and structure.
3636
"""
@@ -43,7 +43,7 @@ struct Writer:
4343

4444
fn write_key_value(mut self, key: String, value: String):
4545
"""Write a key-value pair to the buffer.
46-
46+
4747
Args:
4848
key: Key name.
4949
value: Value string.
@@ -52,29 +52,29 @@ struct Writer:
5252

5353
fn write_section(mut self, section_name: String):
5454
"""Write a section header to the buffer.
55-
55+
5656
Args:
5757
section_name: Section name (without brackets).
5858
"""
5959
self.buffer += "[" + section_name + "]\n"
6060

6161
fn write(mut self, data: Dict[String, Dict[String, String]]) raises -> String:
6262
"""Write Dict structure to INI format.
63-
63+
6464
Args:
6565
data: Nested dictionary where top-level keys are section names
6666
and values are dictionaries of key-value pairs.
67-
67+
6868
Returns:
6969
INI formatted string.
70-
70+
7171
Example:
7272
```mojo
7373
var data = Dict[String, Dict[String, String]]()
7474
data["Server"] = Dict[String, String]()
7575
data["Server"]["host"] = "localhost"
7676
data["Server"]["port"] = "8080"
77-
77+
7878
var writer = Writer()
7979
var ini_text = writer.write(data)
8080
# Output:
@@ -87,7 +87,7 @@ struct Writer:
8787
if "" in data:
8888
for entry in data[""].items():
8989
self.write_key_value(entry.key, entry.value)
90-
90+
9191
# Add blank line after default section if there are other sections
9292
if len(data) > 1:
9393
self.buffer += "\n"
@@ -98,7 +98,7 @@ struct Writer:
9898
# Skip default section (already written)
9999
if section_entry.key == "":
100100
continue
101-
101+
102102
# Add blank line between sections (but not before first section)
103103
if not first_section:
104104
self.buffer += "\n"
@@ -116,21 +116,21 @@ struct Writer:
116116

117117
fn to_ini(data: Dict[String, Dict[String, String]]) raises -> String:
118118
"""Convert Dict structure to INI format string.
119-
119+
120120
Convenience function that handles writing in one step.
121-
121+
122122
Args:
123123
data: Nested dictionary mapping section names to key-value pairs.
124-
124+
125125
Returns:
126126
INI formatted string.
127-
127+
128128
Example:
129129
```mojo
130130
var data = Dict[String, Dict[String, String]]()
131131
data["Database"] = Dict[String, String]()
132132
data["Database"]["host"] = "localhost"
133-
133+
134134
var ini_text = to_ini(data)
135135
print(ini_text)
136136
# Output:

tests/test_lexer.mojo

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn test_empty_input() raises:
1616
"""Test lexing empty string."""
1717
var lexer = Lexer("")
1818
var tokens = lexer.tokenize()
19-
19+
2020
assert_equal(len(tokens), 1, "Should have EOF token")
2121
assert_true(tokens[0].kind == TokenKind.EOF(), "Should be EOF")
2222

@@ -25,7 +25,7 @@ fn test_simple_section() raises:
2525
"""Test lexing a section header."""
2626
var lexer = Lexer("[Database]")
2727
var tokens = lexer.tokenize()
28-
28+
2929
assert_equal(len(tokens), 2, "Should have SECTION + EOF")
3030
assert_true(tokens[0].kind == TokenKind.SECTION(), "First token should be SECTION")
3131
assert_equal(tokens[0].value, "Database", "Section name should be 'Database'")
@@ -36,7 +36,7 @@ fn test_key_value_equals() raises:
3636
"""Test lexing key = value."""
3737
var lexer = Lexer("host = localhost")
3838
var tokens = lexer.tokenize()
39-
39+
4040
# Should be: KEY, EQUALS, VALUE, EOF
4141
assert_equal(len(tokens), 4, "Should have KEY + EQUALS + VALUE + EOF")
4242
assert_true(tokens[0].kind == TokenKind.KEY(), "First should be KEY")
@@ -51,7 +51,7 @@ fn test_hash_comment() raises:
5151
"""Test lexing # style comment."""
5252
var lexer = Lexer("# This is a comment")
5353
var tokens = lexer.tokenize()
54-
54+
5555
assert_equal(len(tokens), 2, "Should have COMMENT + EOF")
5656
assert_true(tokens[0].kind == TokenKind.COMMENT(), "Should be COMMENT")
5757
assert_equal(tokens[0].value, "This is a comment", "Comment text should match")
@@ -61,7 +61,7 @@ fn test_semicolon_comment() raises:
6161
"""Test lexing ; style comment."""
6262
var lexer = Lexer("; Windows-style comment")
6363
var tokens = lexer.tokenize()
64-
64+
6565
assert_equal(len(tokens), 2, "Should have COMMENT + EOF")
6666
assert_true(tokens[0].kind == TokenKind.COMMENT(), "Should be COMMENT")
6767
assert_equal(tokens[0].value, "Windows-style comment", "Comment text should match")
@@ -71,7 +71,7 @@ fn test_section_with_newline() raises:
7171
"""Test section followed by newline."""
7272
var lexer = Lexer("[Server]\n")
7373
var tokens = lexer.tokenize()
74-
74+
7575
assert_equal(len(tokens), 3, "Should have SECTION + NEWLINE + EOF")
7676
assert_true(tokens[0].kind == TokenKind.SECTION(), "First should be SECTION")
7777
assert_equal(tokens[0].value, "Server", "Section should be 'Server'")
@@ -82,15 +82,15 @@ fn test_position_tracking() raises:
8282
"""Test that positions are tracked correctly."""
8383
var lexer = Lexer("[Test]")
8484
var tokens = lexer.tokenize()
85-
85+
8686
assert_equal(tokens[0].pos.line, 1, "Should be on line 1")
8787
assert_equal(tokens[0].pos.column, 1, "Should start at column 1")
8888

8989

9090
fn test_unclosed_section_error() raises:
9191
"""Test error on unclosed section."""
9292
var lexer = Lexer("[Unclosed")
93-
93+
9494
try:
9595
var tokens = lexer.tokenize()
9696
assert_true(False, "Should have raised error for unclosed section")
@@ -104,10 +104,10 @@ fn test_multiline_ini() raises:
104104
var input = """[Database]
105105
host = localhost
106106
port = 5432"""
107-
107+
108108
var lexer = Lexer(input)
109109
var tokens = lexer.tokenize()
110-
110+
111111
# Expected: SECTION, NEWLINE, KEY, EQUALS, (value missing), NEWLINE, KEY, EQUALS, (value missing), EOF
112112
# We need to track context to know when to read values
113113
assert_true(len(tokens) > 5, "Should have multiple tokens")

tests/test_writer.mojo

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Tests serialisation of Dict structures to INI format:
44
- Section headers
5-
- Key-value pairs
5+
- Key-value pairs
66
- Default section (no header)
77
- Multiple sections
88
- Roundtrip (parse → write → parse)
@@ -18,7 +18,7 @@ fn test_empty_dict() raises:
1818
"""Test writing empty dictionary."""
1919
var data = Dict[String, Dict[String, String]]()
2020
data[""] = Dict[String, String]() # Empty default section
21-
21+
2222
var ini_text = to_ini(data)
2323
assert_equal(ini_text, "", "Empty dict should produce empty string")
2424

@@ -28,9 +28,9 @@ fn test_single_section_single_key() raises:
2828
var data = Dict[String, Dict[String, String]]()
2929
data["Database"] = Dict[String, String]()
3030
data["Database"]["host"] = "localhost"
31-
31+
3232
var ini_text = to_ini(data)
33-
33+
3434
assert_true("[Database]" in ini_text, "Should have section header")
3535
assert_true("host = localhost" in ini_text, "Should have key-value pair")
3636

@@ -42,9 +42,9 @@ fn test_single_section_multiple_keys() raises:
4242
data["Server"]["host"] = "0.0.0.0"
4343
data["Server"]["port"] = "8080"
4444
data["Server"]["debug"] = "true"
45-
45+
4646
var ini_text = to_ini(data)
47-
47+
4848
assert_true("[Server]" in ini_text, "Should have section header")
4949
assert_true("host = 0.0.0.0" in ini_text, "Should have host")
5050
assert_true("port = 8080" in ini_text, "Should have port")
@@ -58,9 +58,9 @@ fn test_multiple_sections() raises:
5858
data["Database"]["host"] = "localhost"
5959
data["Server"] = Dict[String, String]()
6060
data["Server"]["port"] = "8080"
61-
61+
6262
var ini_text = to_ini(data)
63-
63+
6464
assert_true("[Database]" in ini_text, "Should have Database section")
6565
assert_true("[Server]" in ini_text, "Should have Server section")
6666
assert_true("host = localhost" in ini_text, "Should have Database host")
@@ -73,9 +73,9 @@ fn test_default_section() raises:
7373
data[""] = Dict[String, String]() # Default section
7474
data[""]["key1"] = "value1"
7575
data[""]["key2"] = "value2"
76-
76+
7777
var ini_text = to_ini(data)
78-
78+
7979
# Default section should NOT have a header
8080
assert_true("[" not in ini_text, "Should not have section headers")
8181
assert_true("key1 = value1" in ini_text, "Should have key1")
@@ -89,9 +89,9 @@ fn test_default_and_named_sections() raises:
8989
data[""]["global_key"] = "global_value"
9090
data["Section"] = Dict[String, String]()
9191
data["Section"]["key"] = "value"
92-
92+
9393
var ini_text = to_ini(data)
94-
94+
9595
# Default section keys come first, no header
9696
assert_true("global_key = global_value" in ini_text, "Should have global key")
9797
# Then named section with header
@@ -108,16 +108,16 @@ port = 5432
108108
[Server]
109109
debug = true
110110
timeout = 30"""
111-
111+
112112
# Parse original
113113
var data1 = parse(original_ini)
114-
114+
115115
# Write to INI
116116
var written_ini = to_ini(data1)
117-
117+
118118
# Parse written INI
119119
var data2 = parse(written_ini)
120-
120+
121121
# Should have same sections and values
122122
assert_equal(data1["Database"]["host"], data2["Database"]["host"])
123123
assert_equal(data1["Database"]["port"], data2["Database"]["port"])
@@ -132,11 +132,11 @@ fn test_roundtrip_with_special_chars() raises:
132132
data1["Test"]["email"] = "user@example.com"
133133
data1["Test"]["url"] = "https://example.com/path?query=1"
134134
data1["Test"]["path"] = "/path/with spaces/file"
135-
135+
136136
# Write and parse back
137137
var ini_text = to_ini(data1)
138138
var data2 = parse(ini_text)
139-
139+
140140
# Should preserve special characters
141141
assert_equal(data1["Test"]["email"], data2["Test"]["email"])
142142
assert_equal(data1["Test"]["url"], data2["Test"]["url"])
@@ -149,9 +149,9 @@ fn test_empty_values() raises:
149149
data["Test"] = Dict[String, String]()
150150
data["Test"]["empty_key"] = ""
151151
data["Test"]["normal_key"] = "value"
152-
152+
153153
var ini_text = to_ini(data)
154-
154+
155155
assert_true("empty_key = " in ini_text, "Should have empty value")
156156
assert_true("normal_key = value" in ini_text, "Should have normal value")
157157

0 commit comments

Comments
 (0)