mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
chore(curriculum): use ast helpers step 5 case converter (#57030)
This commit is contained in:
+16
-8
@@ -18,11 +18,21 @@ You should assign the modified character to a variable named `converted_characte
|
||||
```js
|
||||
({
|
||||
test: () => {
|
||||
const transformedCode = code.replace(/\r/g, "");
|
||||
const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case");
|
||||
const { function_body } = convert_to_snake_case;
|
||||
|
||||
assert.match(function_body, / +converted_character\s*=\s*("|')_\1\s*\+\s*char\.lower\s*\(\s*\)/);
|
||||
assert(runPython(`
|
||||
converted_character_variable = (
|
||||
_Node(_code)
|
||||
.find_function("convert_to_snake_case")
|
||||
.find_for_loops()[0]
|
||||
.find_ifs()[0]
|
||||
.find_variable("converted_character")
|
||||
)
|
||||
|
||||
converted_character_variable.is_equivalent(
|
||||
"converted_character = '_' + char.lower()"
|
||||
) or converted_character_variable.is_equivalent(
|
||||
"converted_character = f'_{char.lower()}'"
|
||||
)
|
||||
`));
|
||||
}
|
||||
})
|
||||
```
|
||||
@@ -32,9 +42,7 @@ You should not have `pass` in your `if` statement.
|
||||
```js
|
||||
({
|
||||
test: () => {
|
||||
const commentless_code = __helpers.python.removeComments(code);
|
||||
const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+char\.isupper\s*\(\s*\)\s*/);
|
||||
assert.notMatch(block_body, /pass/);
|
||||
assert(runPython(`not _Node(_code).find_function("convert_to_snake_case").find_for_loops()[0].find_ifs()[0].has_stmt("pass")`));
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user