Andriamanitra / coctus

Command line tool for playing Clash of Code locally
MIT License
4 stars 2 forks source link

Variable casing doesn't match CodinGame #76

Closed Andriamanitra closed 1 month ago

Andriamanitra commented 1 month ago

Turns out CodinGame handles edge cases different than us in their casing logic:

    #[test]
    fn test_weirdness() {
        let word = "ABC1ABc1aBC1AbC1abc1";

        // (works) CodinGame snake_casing for C++, Python, Perl
        assert_eq!(VariableNameOptions::convert_to_snake_case(word), "abc1abc_1a_bc1ab_c1abc_1");

        // (FAILS) CodinGame snake_casing for C:
        assert_eq!(VariableNameOptions::convert_to_snake_case(word), "abc_1abc_1a_bc_1ab_c_1abc_1");

        // (FAILS) CodinGame casing for Pascal, Bash, Dart, Clojure(??), F#(??),
        // Groovy(??), Lua, ObjC
        // note that CodinGame does not even capitalize the word, it just keeps the capital 'A'
        assert_eq!(VariableNameOptions::convert_to_pascal_case(word), "ABC1ABc1aBC1AbC1abc1");

        // (FAILS) CodinGame casing for C#, D, Go, Java, JS/TS, Kotlin, PHP, Scala,
        // Swift, VB.NET
        assert_eq!(VariableNameOptions::convert_to_camel_case(word), "abc1ABc1aBc1AbC1abc1");

        // (doesn't exist) CodinGame casing for Haskell, OCaml
        // abc1abc1abc1abc1abc1
    }

I'm not sure how we want to handle this. I don't think it's necessary to match CodinGame behavior exactly but currently our convert_to_pascal_case would produce "ABC1aBc1aBC1AbC1abc1" which matches neither my expectation for PascalCase nor CodinGame behavior.

The difference in snake_casing C we can probably just ignore, I don't see any valid reason to have different snake casing for C?