-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.py
74 lines (65 loc) · 2.39 KB
/
test_utils.py
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
from utils import extract_code_blocks, translate_code, replace_code_blocks
def test_extract_code_blocks():
sample_markdown = """
# Sample Markdown
Here's some code:
```python
print("Hello, World!")
```
And some more code:
```python
print("Hello, Again!")
```
"""
extracted_blocks = extract_code_blocks(sample_markdown)
print(extracted_blocks)
assert len(extracted_blocks) == 2
assert extracted_blocks[0] == '```python\nprint("Hello, World!")\n```'
assert extracted_blocks[1] == '```python\nprint("Hello, Again!")\n```'
def test_translate_code():
sample_code = 'print("Hello, World!")'
translated = translate_code(sample_code, 'python', 'javascript')
assert translated == """Translate the following python code to javascript:
print("Hello, World!")"""
def test_replace_code_blocks():
sample_markdown = """
# Sample Markdown
Here's some code:
```python
print("Hello, World!")
```
"""
translated_markdown = """
# Sample Markdown
Here's some code:
```js
console.log("Hello, World!");
```
"""
replaced_content = replace_code_blocks(sample_markdown, ['```python\nprint("Hello, World!")\n```\n'], ['```js\nconsole.log("Hello, World!");\n```\n'])
print(replaced_content)
assert replaced_content == translated_markdown
"""
```cpp
255, 0377, 0xff // Integers (decimal, octal, hex)
2147483647L, 0x7fffffffl // Long (32-bit) integers
123.0, 1.23e2 // double (real) numbers
'a', '\\141', '\\x61' // Character (literal, octal, hex)
'\\n', '\\\\', '\\'', '\\"' // Newline, backslash, single quote, double quote
"string\\n" // Array of characters ending with newline and \\0
"hello" "world" // Concatenated strings
true, false // bool constants 1 and 0
nullptr // Pointer type with the address of 0
```
"""
"""csharp
255, 0377, 0xff // Integers (decimal, octal (not supported in C#), hex)
int.MaxValue, 0x7fffffff // Int32 (32-bit) integers
123.0, 1.23e2 // double (real) numbers
'a', '\141', '\x61' // Character (literal, octal, hex)
'\n', '\\', '\'', '\"' // Newline, backslash, single quote, double quote
"string\n" // String ending with newline
"hello" + "world" // Concatenated strings
true, false // bool constants true and false
null // Null reference for reference types in C#
"""