sway_error/
warning.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
use crate::{
    diagnostic::{Code, Diagnostic, Hint, Issue, Reason, ToDiagnostic},
    formatting::Indent,
};

use core::fmt;

use either::Either;

use sway_types::{Ident, IdentUnique, SourceId, Span, Spanned};

// TODO: since moving to using Idents instead of strings,
// the warning_content will usually contain a duplicate of the span.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CompileWarning {
    pub span: Span,
    pub warning_content: Warning,
}

impl Spanned for CompileWarning {
    fn span(&self) -> Span {
        self.span.clone()
    }
}

impl CompileWarning {
    pub fn to_friendly_warning_string(&self) -> String {
        self.warning_content.to_string()
    }

    pub fn source_id(&self) -> Option<SourceId> {
        self.span.source_id().cloned()
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Warning {
    NonClassCaseStructName {
        struct_name: Ident,
    },
    NonClassCaseTypeParameter {
        name: Ident,
    },
    NonClassCaseTraitName {
        name: Ident,
    },
    NonClassCaseEnumName {
        enum_name: Ident,
    },
    NonClassCaseEnumVariantName {
        variant_name: Ident,
    },
    NonSnakeCaseStructFieldName {
        field_name: Ident,
    },
    NonSnakeCaseFunctionName {
        name: Ident,
    },
    NonScreamingSnakeCaseConstName {
        name: Ident,
    },
    UnusedReturnValue {
        r#type: String,
    },
    SimilarMethodFound {
        lib: Ident,
        module: Ident,
        name: Ident,
    },
    ShadowsOtherSymbol {
        name: Ident,
    },
    AsmBlockIsEmpty,
    UninitializedAsmRegShadowsItem {
        /// Text "Constant" or "Configurable" or "Variable".
        /// Denotes the type of the `item` that shadows the uninitialized ASM register.
        constant_or_configurable_or_variable: &'static str,
        /// The name of the item that shadows the register, that points to the name in
        /// the item declaration.
        item: IdentUnique,
    },
    OverridingTraitImplementation,
    DeadDeclaration,
    DeadEnumDeclaration,
    DeadFunctionDeclaration,
    DeadStructDeclaration,
    DeadTrait,
    UnreachableCode,
    DeadEnumVariant {
        variant_name: Ident,
    },
    DeadMethod,
    StructFieldNeverRead,
    ShadowingReservedRegister {
        reg_name: Ident,
    },
    DeadStorageDeclaration,
    DeadStorageDeclarationForFunction {
        unneeded_attrib: String,
    },
    MatchExpressionUnreachableArm {
        match_value: Span,
        match_type: String,
        // Either preceding non catch-all arms or a single interior catch-all arm.
        preceding_arms: Either<Vec<Span>, Span>,
        unreachable_arm: Span,
        is_last_arm: bool,
        is_catch_all_arm: bool,
    },
    UnrecognizedAttribute {
        attrib_name: Ident,
    },
    AttributeExpectedNumberOfArguments {
        attrib_name: Ident,
        received_args: usize,
        expected_min_len: usize,
        expected_max_len: Option<usize>,
    },
    UnexpectedAttributeArgumentValue {
        attrib_name: Ident,
        received_value: String,
        expected_values: Vec<String>,
    },
    EffectAfterInteraction {
        effect: String,
        effect_in_suggestion: String,
        block_name: Ident,
    },
    ModulePrivacyDisabled,
    UsingDeprecated {
        message: String,
    },
    DuplicatedStorageKey {
        first_field: IdentUnique,
        first_field_full_name: String,
        first_field_key_is_compiler_generated: bool,
        second_field: IdentUnique,
        second_field_full_name: String,
        second_field_key_is_compiler_generated: bool,
        key: String,
        // True if the experimental feature `storage_domains` is used.
        experimental_storage_domains: bool,
    },
}

impl fmt::Display for Warning {
    // This trait requires `fmt` with this exact signature.
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        use sway_types::style::*;
        use Warning::*;
        match self {
            NonClassCaseStructName { struct_name } => {
                write!(f,
                "Struct name \"{}\" is not idiomatic. Structs should have a ClassCase name, like \
                 \"{}\".",
                struct_name,
                to_upper_camel_case(struct_name.as_str())
            )
            }
            NonClassCaseTypeParameter { name } => {
                write!(f,
                "Type parameter \"{}\" is not idiomatic. TypeParameters should have a ClassCase name, like \
                 \"{}\".",
                name,
                to_upper_camel_case(name.as_str())
            )
            }
            NonClassCaseTraitName { name } => {
                write!(f,
                "Trait name \"{}\" is not idiomatic. Traits should have a ClassCase name, like \
                 \"{}\".",
                name,
                to_upper_camel_case(name.as_str())
            )
            }
            NonClassCaseEnumName { enum_name } => write!(
                f,
                "Enum \"{}\"'s capitalization is not idiomatic. Enums should have a ClassCase \
                 name, like \"{}\".",
                enum_name,
                to_upper_camel_case(enum_name.as_str())
            ),
            NonSnakeCaseStructFieldName { field_name } => write!(
                f,
                "Struct field name \"{}\" is not idiomatic. Struct field names should have a \
                 snake_case name, like \"{}\".",
                field_name,
                to_snake_case(field_name.as_str())
            ),
            NonClassCaseEnumVariantName { variant_name } => write!(
                f,
                "Enum variant name \"{}\" is not idiomatic. Enum variant names should be \
                 ClassCase, like \"{}\".",
                variant_name,
                to_upper_camel_case(variant_name.as_str())
            ),
            NonSnakeCaseFunctionName { name } => {
                write!(f,
                "Function name \"{}\" is not idiomatic. Function names should be snake_case, like \
                 \"{}\".",
                name,
                to_snake_case(name.as_str())
            )
            }
            NonScreamingSnakeCaseConstName { name } => {
                write!(
                    f,
                    "Constant name \"{name}\" is not idiomatic. Constant names should be SCREAMING_SNAKE_CASE, like \
                    \"{}\".",
                    to_screaming_snake_case(name.as_str()),
                )
            },
            UnusedReturnValue { r#type } => write!(
                f,
                "This returns a value of type {type}, which is not assigned to anything and is \
                 ignored."
            ),
            SimilarMethodFound { lib, module, name } => write!(
                f,
                "A method with the same name was found for type {name} in dependency \"{lib}::{module}\". \
                 Traits must be in scope in order to access their methods. "
            ),
            ShadowsOtherSymbol { name } => write!(
                f,
                "This shadows another symbol in this scope with the same name \"{name}\"."
            ),
            AsmBlockIsEmpty => write!(
                f,
                "This ASM block is empty."
            ),
            UninitializedAsmRegShadowsItem { constant_or_configurable_or_variable, item } => write!(
                f,
                "This uninitialized register is shadowing a {}. You probably meant to also initialize it, like \"{item}: {item}\".",
                constant_or_configurable_or_variable.to_ascii_lowercase(),
            ),
            OverridingTraitImplementation => write!(
                f,
                "This trait implementation overrides another one that was previously defined."
            ),
            DeadDeclaration => write!(f, "This declaration is never used."),
            DeadEnumDeclaration => write!(f, "This enum is never used."),
            DeadStructDeclaration => write!(f, "This struct is never used."),
            DeadFunctionDeclaration => write!(f, "This function is never called."),
            UnreachableCode => write!(f, "This code is unreachable."),
            DeadEnumVariant { variant_name } => {
                write!(f, "Enum variant {variant_name} is never constructed.")
            }
            DeadTrait => write!(f, "This trait is never implemented."),
            DeadMethod => write!(f, "This method is never called."),
            StructFieldNeverRead => write!(f, "This struct field is never accessed."),
            ShadowingReservedRegister { reg_name } => write!(
                f,
                "This register declaration shadows the reserved register, \"{reg_name}\"."
            ),
            DeadStorageDeclaration => write!(
                f,
                "This storage declaration is never accessed and can be removed."
            ),
            DeadStorageDeclarationForFunction { unneeded_attrib } => write!(
                f,
                "This function's storage attributes declaration does not match its \
                 actual storage access pattern: '{unneeded_attrib}' attribute(s) can be removed."
            ),
            MatchExpressionUnreachableArm { .. } => write!(f, "This match arm is unreachable."),
            UnrecognizedAttribute {attrib_name} => write!(f, "Unknown attribute: \"{attrib_name}\"."),
            AttributeExpectedNumberOfArguments {attrib_name, received_args, expected_min_len, expected_max_len } => write!(
                f,
                "Attribute: \"{attrib_name}\" expected {} argument(s) received {received_args}.",
                if let Some(expected_max_len) = expected_max_len {
                    if expected_min_len == expected_max_len {
                        format!("exactly {expected_min_len}")
                    } else {
                        format!("between {expected_min_len} and {expected_max_len}")
                    }
                } else {
                    format!("at least {expected_min_len}")
                }
            ),
            UnexpectedAttributeArgumentValue {attrib_name, received_value, expected_values } => write!(
                f,
                "Unexpected attribute value: \"{received_value}\" for attribute: \"{attrib_name}\" expected value {}",
                expected_values.iter().map(|v| format!("\"{v}\"")).collect::<Vec<_>>().join(" or ")
            ),
            EffectAfterInteraction {effect, effect_in_suggestion, block_name} =>
                write!(f, "{effect} after external contract interaction in function or method \"{block_name}\". \
                          Consider {effect_in_suggestion} before calling another contract"),
            ModulePrivacyDisabled => write!(f, "Module privacy rules will soon change to make modules private by default.
                                            You can enable the new behavior with the --experimental-private-modules flag, which will become the default behavior in a later release.
                                            More details are available in the related RFC: https://github.com/FuelLabs/sway-rfcs/blob/master/rfcs/0008-private-modules.md"),
            UsingDeprecated { message } => write!(f, "{}", message),
            DuplicatedStorageKey { first_field_full_name, second_field_full_name, key, .. } =>
                write!(f, "Two storage fields have the same storage key.\nFirst field: {first_field_full_name}\nSecond field: {second_field_full_name}\nKey: {key}"),
        }
    }
}

#[allow(dead_code)]
const FUTURE_HARD_ERROR_HELP: &str =
    "In future versions of Sway this warning will become a hard error.";

impl ToDiagnostic for CompileWarning {
    fn to_diagnostic(&self, source_engine: &sway_types::SourceEngine) -> Diagnostic {
        let code = Code::warnings;
        use sway_types::style::*;
        use Warning::*;
        match &self.warning_content {
            NonScreamingSnakeCaseConstName { name } => Diagnostic {
                reason: Some(Reason::new(code(1), "Constant name is not idiomatic".to_string())),
                issue: Issue::warning(
                    source_engine,
                    name.span(),
                    format!("Constant \"{name}\" should be SCREAMING_SNAKE_CASE."),
                ),
                hints: vec![
                    Hint::help(
                        source_engine,
                        name.span(),
                        format!("Consider renaming it to, e.g., \"{}\".", to_screaming_snake_case(name.as_str())),
                    ),
                ],
                help: vec![
                    format!("In Sway, ABIs, structs, traits, and enums are CapitalCase."),
                    format!("Modules, variables, and functions are snake_case, while constants are SCREAMING_SNAKE_CASE."),
                ],
            },
            MatchExpressionUnreachableArm { match_value, match_type, preceding_arms, unreachable_arm, is_last_arm, is_catch_all_arm } => Diagnostic {
                reason: Some(Reason::new(code(1), "Match arm is unreachable".to_string())),
                issue: Issue::warning(
                    source_engine,
                    unreachable_arm.clone(),
                    match (*is_last_arm, *is_catch_all_arm) {
                        (true, true) => format!("Last catch-all match arm `{}` is unreachable.", unreachable_arm.as_str()),
                        _ => format!("Match arm `{}` is unreachable.", unreachable_arm.as_str())
                    }
                ),
                hints: vec![
                    Hint::info(
                        source_engine,
                        match_value.clone(),
                        format!("The expression to match on is of type \"{match_type}\".")
                    ),
                    if preceding_arms.is_right() {
                        Hint::help(
                            source_engine,
                            preceding_arms.as_ref().unwrap_right().clone(),
                            format!("Catch-all arm `{}` makes all match arms below it unreachable.", preceding_arms.as_ref().unwrap_right().as_str())
                        )
                    }
                    else {
                        Hint::info(
                            source_engine,
                            Span::join_all(preceding_arms.as_ref().unwrap_left().clone()),
                            if *is_last_arm {
                                format!("Preceding match arms already match all possible values of `{}`.", match_value.as_str())
                            }
                            else {
                                format!("Preceding match arms already match all the values that `{}` can match.", unreachable_arm.as_str())
                            }
                        )
                    }
                ],
                help: if preceding_arms.is_right() {
                    let catch_all_arm = preceding_arms.as_ref().unwrap_right().as_str();
                    vec![
                        format!("Catch-all patterns make sense only in last match arms."),
                        format!("Consider removing the catch-all arm `{catch_all_arm}` or making it the last arm."),
                        format!("Consider removing the unreachable arms below the `{catch_all_arm}` arm."),
                    ]
                }
                else if *is_last_arm && *is_catch_all_arm {
                    vec![
                        format!("Catch-all patterns are often used in last match arms."),
                        format!("But in this case, the preceding arms already match all possible values of `{}`.", match_value.as_str()),
                        format!("Consider removing the unreachable last catch-all arm."),
                    ]
                }
                else {
                    vec![
                        format!("Consider removing the unreachable arm."),
                    ]
                }
            },
            UninitializedAsmRegShadowsItem { constant_or_configurable_or_variable, item } => Diagnostic {
                reason: Some(Reason::new(code(1), format!("Uninitialized ASM register is shadowing a {}", constant_or_configurable_or_variable.to_ascii_lowercase()))),
                issue: Issue::warning(
                    source_engine,
                    self.span(),
                    format!("Uninitialized register \"{item}\" is shadowing a {} of the same name.", constant_or_configurable_or_variable.to_ascii_lowercase()),
                ),
                hints: {
                    let mut hints = vec![
                        Hint::info(
                            source_engine,
                            item.span(),
                            format!("{constant_or_configurable_or_variable} \"{item}\" is declared here.")
                        ),
                    ];

                    hints.append(&mut Hint::multi_help(
                        source_engine,
                        &self.span(),
                        vec![
                            format!("Are you trying to initialize the register to the value of the {}?", constant_or_configurable_or_variable.to_ascii_lowercase()),
                            format!("In that case, you must do it explicitly: `{item}: {item}`."),
                            format!("Otherwise, to avoid the confusion with the shadowed {}, consider renaming the register \"{item}\".", constant_or_configurable_or_variable.to_ascii_lowercase()),
                        ]
                    ));

                    hints
                },
                help: vec![],
            },
            AsmBlockIsEmpty => Diagnostic {
                reason: Some(Reason::new(code(1), "ASM block is empty".to_string())),
                issue: Issue::warning(
                    source_engine,
                    self.span(),
                    "This ASM block is empty.".to_string(),
                ),
                hints: vec![],
                help: vec![
                    "Consider adding assembly instructions or a return register to the ASM block, or removing the block altogether.".to_string(),
                ],
            },
            DuplicatedStorageKey { first_field, first_field_full_name, first_field_key_is_compiler_generated, second_field, second_field_full_name, second_field_key_is_compiler_generated, key, experimental_storage_domains } => Diagnostic {
                reason: Some(Reason::new(code(1), "Two storage fields have the same storage key".to_string())),
                issue: Issue::warning(
                    source_engine,
                    first_field.span(),
                    format!("\"{first_field_full_name}\" has the same storage key as \"{second_field_full_name}\"."),
                ),
                hints: vec![
                    Hint::info(
                        source_engine,
                        second_field.span(),
                        format!("\"{second_field_full_name}\" is declared here."),
                    ),
                ],
                help: vec![
                    if *first_field_key_is_compiler_generated || *second_field_key_is_compiler_generated {
                        format!("The key of \"{}\" is generated by the compiler using the following formula:",
                            if *first_field_key_is_compiler_generated {
                                first_field_full_name
                            } else {
                                second_field_full_name
                            }
                        )
                    } else {
                        "Both keys are explicitly defined by using the `in` keyword.".to_string()
                    },
                    if *first_field_key_is_compiler_generated || *second_field_key_is_compiler_generated {
                        if *experimental_storage_domains {
                            format!("{}sha256((0u8, \"{}\"))",
                                Indent::Single,
                                if *first_field_key_is_compiler_generated {
                                    first_field_full_name
                                } else {
                                    second_field_full_name
                                }
                            )
                        } else {
                            format!("{}sha256(\"{}\")",
                                Indent::Single,
                                if *first_field_key_is_compiler_generated {
                                    first_field_full_name
                                } else {
                                    second_field_full_name
                                }
                            )
                        }
                    } else {
                        Diagnostic::help_none()
                    },
                    format!("The common key is: {key}.")
                ],
            },
           _ => Diagnostic {
                    // TODO: Temporary we use self here to achieve backward compatibility.
                    //       In general, self must not be used and will not be used once we
                    //       switch to our own #[error] macro. All the values for the formatting
                    //       of a diagnostic must come from the enum variant parameters.
                    issue: Issue::warning(source_engine, self.span(), format!("{}", self.warning_content)),
                    ..Default::default()
                }
        }
    }
}

#[cfg(test)]
mod test {
    use sway_types::style::*;

    #[test]
    fn detect_styles() {
        let snake_cases = [
            "hello",
            "__hello",
            "blah32",
            "some_words_here",
            "___some_words_here",
        ];
        let screaming_snake_cases = ["SOME_WORDS_HERE", "___SOME_WORDS_HERE"];
        let upper_camel_cases = [
            "Hello",
            "__Hello",
            "Blah32",
            "SomeWordsHere",
            "___SomeWordsHere",
        ];
        let screaming_snake_case_or_upper_camel_case_idents = ["HELLO", "__HELLO", "BLAH32"];
        let styleless_idents = ["Mix_Of_Things", "__Mix_Of_Things", "FooBar_123"];
        for name in &snake_cases {
            assert!(is_snake_case(name));
            assert!(!is_screaming_snake_case(name));
            assert!(!is_upper_camel_case(name));
        }
        for name in &screaming_snake_cases {
            assert!(!is_snake_case(name));
            assert!(is_screaming_snake_case(name));
            assert!(!is_upper_camel_case(name));
        }
        for name in &upper_camel_cases {
            assert!(!is_snake_case(name));
            assert!(!is_screaming_snake_case(name));
            assert!(is_upper_camel_case(name));
        }
        for name in &screaming_snake_case_or_upper_camel_case_idents {
            assert!(!is_snake_case(name));
            assert!(is_screaming_snake_case(name));
            assert!(is_upper_camel_case(name));
        }
        for name in &styleless_idents {
            assert!(!is_snake_case(name));
            assert!(!is_screaming_snake_case(name));
            assert!(!is_upper_camel_case(name));
        }
    }

    #[test]
    fn convert_to_snake_case() {
        assert_eq!("hello", to_snake_case("HELLO"));
        assert_eq!("___hello", to_snake_case("___HELLO"));
        assert_eq!("blah32", to_snake_case("BLAH32"));
        assert_eq!("some_words_here", to_snake_case("SOME_WORDS_HERE"));
        assert_eq!("___some_words_here", to_snake_case("___SOME_WORDS_HERE"));
        assert_eq!("hello", to_snake_case("Hello"));
        assert_eq!("___hello", to_snake_case("___Hello"));
        assert_eq!("blah32", to_snake_case("Blah32"));
        assert_eq!("some_words_here", to_snake_case("SomeWordsHere"));
        assert_eq!("___some_words_here", to_snake_case("___SomeWordsHere"));
        assert_eq!("some_words_here", to_snake_case("someWordsHere"));
        assert_eq!("___some_words_here", to_snake_case("___someWordsHere"));
        assert_eq!("mix_of_things", to_snake_case("Mix_Of_Things"));
        assert_eq!("__mix_of_things", to_snake_case("__Mix_Of_Things"));
        assert_eq!("foo_bar_123", to_snake_case("FooBar_123"));
    }

    #[test]
    fn convert_to_screaming_snake_case() {
        assert_eq!("HELLO", to_screaming_snake_case("hello"));
        assert_eq!("___HELLO", to_screaming_snake_case("___hello"));
        assert_eq!("BLAH32", to_screaming_snake_case("blah32"));
        assert_eq!(
            "SOME_WORDS_HERE",
            to_screaming_snake_case("some_words_here")
        );
        assert_eq!(
            "___SOME_WORDS_HERE",
            to_screaming_snake_case("___some_words_here")
        );
        assert_eq!("HELLO", to_screaming_snake_case("Hello"));
        assert_eq!("___HELLO", to_screaming_snake_case("___Hello"));
        assert_eq!("BLAH32", to_screaming_snake_case("Blah32"));
        assert_eq!("SOME_WORDS_HERE", to_screaming_snake_case("SomeWordsHere"));
        assert_eq!(
            "___SOME_WORDS_HERE",
            to_screaming_snake_case("___SomeWordsHere")
        );
        assert_eq!("SOME_WORDS_HERE", to_screaming_snake_case("someWordsHere"));
        assert_eq!(
            "___SOME_WORDS_HERE",
            to_screaming_snake_case("___someWordsHere")
        );
        assert_eq!("MIX_OF_THINGS", to_screaming_snake_case("Mix_Of_Things"));
        assert_eq!(
            "__MIX_OF_THINGS",
            to_screaming_snake_case("__Mix_Of_Things")
        );
        assert_eq!("FOO_BAR_123", to_screaming_snake_case("FooBar_123"));
    }

    #[test]
    fn convert_to_upper_camel_case() {
        assert_eq!("Hello", to_upper_camel_case("hello"));
        assert_eq!("___Hello", to_upper_camel_case("___hello"));
        assert_eq!("Blah32", to_upper_camel_case("blah32"));
        assert_eq!("SomeWordsHere", to_upper_camel_case("some_words_here"));
        assert_eq!(
            "___SomeWordsHere",
            to_upper_camel_case("___some_words_here")
        );
        assert_eq!("Hello", to_upper_camel_case("HELLO"));
        assert_eq!("___Hello", to_upper_camel_case("___HELLO"));
        assert_eq!("Blah32", to_upper_camel_case("BLAH32"));
        assert_eq!("SomeWordsHere", to_upper_camel_case("SOME_WORDS_HERE"));
        assert_eq!(
            "___SomeWordsHere",
            to_upper_camel_case("___SOME_WORDS_HERE")
        );
        assert_eq!("SomeWordsHere", to_upper_camel_case("someWordsHere"));
        assert_eq!("___SomeWordsHere", to_upper_camel_case("___someWordsHere"));
        assert_eq!("MixOfThings", to_upper_camel_case("Mix_Of_Things"));
        assert_eq!("__MixOfThings", to_upper_camel_case("__Mix_Of_Things"));
        assert_eq!("FooBar123", to_upper_camel_case("FooBar_123"));
    }
}