Merge pull request #214 from Incubaid/development_fix_codeparser_tests
refactor: Improve const and param parsing logic
This commit is contained in:
@@ -11,8 +11,13 @@ pub fn parse_const(code_ string) !Const {
|
|||||||
if !code.contains('=') {
|
if !code.contains('=') {
|
||||||
return error('code <${code_}> is not of const')
|
return error('code <${code_}> is not of const')
|
||||||
}
|
}
|
||||||
|
mut name := code.split('=')[0].trim_space()
|
||||||
|
// Strip 'const ' prefix if present
|
||||||
|
if name.starts_with('const ') {
|
||||||
|
name = name.trim_string_left('const ').trim_space()
|
||||||
|
}
|
||||||
return Const{
|
return Const{
|
||||||
name: code.split('=')[0].trim_space()
|
name: name
|
||||||
value: code.split('=')[1].trim_space()
|
value: code.split('=')[1].trim_space()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ pub fn (p Param) typescript() string {
|
|||||||
pub fn parse_param(code_ string) !Param {
|
pub fn parse_param(code_ string) !Param {
|
||||||
mut code := code_.trim_space()
|
mut code := code_.trim_space()
|
||||||
|
|
||||||
|
// Handle empty string (void return type)
|
||||||
|
if code == '' {
|
||||||
|
return Param{}
|
||||||
|
}
|
||||||
|
|
||||||
if code == '!' {
|
if code == '!' {
|
||||||
return Param{
|
return Param{
|
||||||
is_result: true
|
is_result: true
|
||||||
@@ -60,6 +65,13 @@ pub fn parse_param(code_ string) !Param {
|
|||||||
}
|
}
|
||||||
split := code.split(' ').filter(it != '')
|
split := code.split(' ').filter(it != '')
|
||||||
|
|
||||||
|
// Handle empty split (void return type after mut check)
|
||||||
|
if split.len == 0 {
|
||||||
|
return Param{
|
||||||
|
mutable: is_mut
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if split.len == 1 {
|
if split.len == 1 {
|
||||||
// means anonymous param
|
// means anonymous param
|
||||||
return Param{
|
return Param{
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ fn test_comprehensive_code_parsing() {
|
|||||||
console.print_lf(1)
|
console.print_lf(1)
|
||||||
|
|
||||||
// Run all tests
|
// Run all tests
|
||||||
test_module_parsing()
|
check_module_parsing()!
|
||||||
test_struct_parsing()
|
check_struct_parsing()
|
||||||
test_function_parsing()
|
check_function_parsing()!
|
||||||
test_imports_and_modules()
|
check_imports_and_modules()
|
||||||
test_type_system()
|
check_type_system()
|
||||||
test_visibility_modifiers()
|
check_visibility_modifiers()
|
||||||
test_method_parsing()
|
check_method_parsing()!
|
||||||
test_constants_parsing()
|
check_constants_parsing()
|
||||||
|
|
||||||
console.print_green('✓ All comprehensive tests passed!')
|
console.print_green('✓ All comprehensive tests passed!')
|
||||||
console.print_lf(1)
|
console.print_lf(1)
|
||||||
@@ -74,7 +74,7 @@ fn copy_directory(src string, dst string) ! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_module_parsing() {
|
fn check_module_parsing() ! {
|
||||||
console.print_header('Test 1: Module and File Parsing')
|
console.print_header('Test 1: Module and File Parsing')
|
||||||
|
|
||||||
mut myparser := new(path: '/tmp/codeparsertest', recursive: true)!
|
mut myparser := new(path: '/tmp/codeparsertest', recursive: true)!
|
||||||
@@ -98,7 +98,7 @@ fn test_module_parsing() {
|
|||||||
console.print_lf(1)
|
console.print_lf(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_struct_parsing() {
|
fn check_struct_parsing() {
|
||||||
console.print_header('Test 2: Struct Parsing')
|
console.print_header('Test 2: Struct Parsing')
|
||||||
|
|
||||||
models_file := os.join_path('/tmp/codeparsertest', 'models.v')
|
models_file := os.join_path('/tmp/codeparsertest', 'models.v')
|
||||||
@@ -145,7 +145,7 @@ fn test_struct_parsing() {
|
|||||||
console.print_lf(1)
|
console.print_lf(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_function_parsing() {
|
fn check_function_parsing() ! {
|
||||||
console.print_header('Test 3: Function Parsing')
|
console.print_header('Test 3: Function Parsing')
|
||||||
|
|
||||||
mut myparser := new(path: '/tmp/codeparsertest', recursive: true)!
|
mut myparser := new(path: '/tmp/codeparsertest', recursive: true)!
|
||||||
@@ -191,7 +191,7 @@ fn test_function_parsing() {
|
|||||||
console.print_lf(1)
|
console.print_lf(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_imports_and_modules() {
|
fn check_imports_and_modules() {
|
||||||
console.print_header('Test 4: Imports and Module Names')
|
console.print_header('Test 4: Imports and Module Names')
|
||||||
|
|
||||||
models_file := os.join_path('/tmp/codeparsertest', 'models.v')
|
models_file := os.join_path('/tmp/codeparsertest', 'models.v')
|
||||||
@@ -222,7 +222,7 @@ fn test_imports_and_modules() {
|
|||||||
console.print_lf(1)
|
console.print_lf(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_type_system() {
|
fn check_type_system() {
|
||||||
console.print_header('Test 5: Type System')
|
console.print_header('Test 5: Type System')
|
||||||
|
|
||||||
models_file := os.join_path('/tmp/codeparsertest', 'models.v')
|
models_file := os.join_path('/tmp/codeparsertest', 'models.v')
|
||||||
@@ -257,7 +257,7 @@ fn test_type_system() {
|
|||||||
console.print_lf(1)
|
console.print_lf(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_visibility_modifiers() {
|
fn check_visibility_modifiers() {
|
||||||
console.print_header('Test 6: Visibility Modifiers')
|
console.print_header('Test 6: Visibility Modifiers')
|
||||||
|
|
||||||
models_file := os.join_path('/tmp/codeparsertest', 'models.v')
|
models_file := os.join_path('/tmp/codeparsertest', 'models.v')
|
||||||
@@ -293,7 +293,7 @@ fn test_visibility_modifiers() {
|
|||||||
console.print_lf(1)
|
console.print_lf(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_method_parsing() {
|
fn check_method_parsing() ! {
|
||||||
console.print_header('Test 7: Method Parsing')
|
console.print_header('Test 7: Method Parsing')
|
||||||
|
|
||||||
mut myparser := new(path: '/tmp/codeparsertest', recursive: true)!
|
mut myparser := new(path: '/tmp/codeparsertest', recursive: true)!
|
||||||
@@ -327,7 +327,7 @@ fn test_method_parsing() {
|
|||||||
console.print_lf(1)
|
console.print_lf(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_constants_parsing() {
|
fn check_constants_parsing() {
|
||||||
console.print_header('Test 8: Constants Parsing')
|
console.print_header('Test 8: Constants Parsing')
|
||||||
|
|
||||||
models_file := os.join_path('/tmp/codeparsertest', 'models.v')
|
models_file := os.join_path('/tmp/codeparsertest', 'models.v')
|
||||||
|
|||||||
Reference in New Issue
Block a user