cooklang / cooklang-swift

Cooklang parser implementation in Swift
https://cooklang.org
MIT License
38 stars 3 forks source link

ConfigParser: first item in section is lost (skipped?) #14

Closed annawidera closed 2 years ago

annawidera commented 2 years ago

Hey! First of all I would like to congratulate you the CookLang idea - it's amazing! You should have seen my mom's face when I opened a code editor to note down a family recipe. 😅

I was reading through the CookInSwift code just out of curiosity and I stumbled upon the ConfigParser's add method. I noticed that first item from every section is skipped by simply creating an empty section (sections[section] = []):

https://github.com/cooklang/CookInSwift/blob/b3b07f3d02cd1e719ca90be28ec222171ecff32a/Sources/CookInSwift/ConfigParser/ConfigParser.swift#L16-L24

Then with surprise I discovered that it's actually expected in the tests:

https://github.com/cooklang/CookInSwift/blob/b3b07f3d02cd1e719ca90be28ec222171ecff32a/Tests/CookInSwiftTests/ConfigParserTests.swift#L14-L40

Please, notice that [fruit and veg] contains 3 elements in textConfig, while expected section content is 2 items only: ["bananas", "beetroots"].

[fruit and veg]
        apples
        bananas
        beetroots
let sections = ["fruit and veg": ["bananas", "beetroots"],
                        "milk and dairy": ["egg"]]

Why is it so? Is it really the expected behavior? I thought I will mention this because it smells like it's not and I think it might be issue hard to discover since it's already covered with passing test.

Happy cooking! 🧑‍🍳

dubadub commented 2 years ago

Thanks @annawidera for reporting, it's definitely a bug.

dubadub commented 2 years ago

The fix was released.