From f633831d71b2f20e916e0bf5358fc72c77cce3cd Mon Sep 17 00:00:00 2001 From: peefy Date: Tue, 17 Sep 2024 00:29:29 +0800 Subject: [PATCH] chore: remove go struct test for KCL api Signed-off-by: peefy --- pkg/tools/gen/genkcl_gostruct_test.go | 2381 ------------------------- 1 file changed, 2381 deletions(-) delete mode 100644 pkg/tools/gen/genkcl_gostruct_test.go diff --git a/pkg/tools/gen/genkcl_gostruct_test.go b/pkg/tools/gen/genkcl_gostruct_test.go deleted file mode 100644 index dc79b6c8..00000000 --- a/pkg/tools/gen/genkcl_gostruct_test.go +++ /dev/null @@ -1,2381 +0,0 @@ -package gen - -import ( - "bytes" - "log" - "strings" - "testing" - - assert2 "github.com/stretchr/testify/assert" -) - -func TestGenKclFromLibGoStruct(t *testing.T) { - var buf bytes.Buffer - opts := &GenKclOptions{} - err := GenKcl(&buf, "../../spec/gpyrpc/gpyrpc.pb.go", nil, opts) - if err != nil { - log.Fatal(err) - } - kclCode := buf.String() - expectedKclCodeFromField := `""" -This file was generated by the KCL auto-gen tool. DO NOT EDIT. -Editing this file might prove futile when you re-run the KCL auto-gen generate command. -""" - -schema Argument: - r""" - Message representing a key-value argument for KCL. - kcl main.k -D name=value - - - Attributes - ---------- - name : str, optional - Name of the argument. - - value : str, optional - Value of the argument. - - """ - - name?: str - value?: str - -schema BuildProgram_Args: - r""" - Message for build program request arguments. - - - Attributes - ---------- - exec_args : ExecProgram_Args, optional - Arguments for executing the program. - - output : str, optional - Output path. - - """ - - exec_args?: ExecProgram_Args - output?: str - -schema BuildProgram_Result: - r""" - Message for build program response. - - - Attributes - ---------- - path : str, optional - Path of the built program. - - """ - - path?: str - -schema CliConfig: - r""" - Message representing KCL CLI configuration. - - - Attributes - ---------- - files : [str], optional - List of files. - - output : str, optional - Output path. - - overrides : [str], optional - List of overrides. - - path_selector : [str], optional - Path selectors. - - strict_range_check : bool, optional - Flag for strict range check. - - disable_none : bool, optional - Flag to disable none values. - - verbose : int, optional - Verbose level. - - debug : bool, optional - Debug flag. - - sort_keys : bool, optional - Flag to sort keys in YAML/JSON results. - - show_hidden : bool, optional - Flag to show hidden attributes. - - include_schema_type_path : bool, optional - Flag to include schema type path in results. - - fast_eval : bool, optional - Flag for fast evaluation. - - """ - - files?: [str] - output?: str - overrides?: [str] - path_selector?: [str] - strict_range_check?: bool - disable_none?: bool - verbose?: int - debug?: bool - sort_keys?: bool - show_hidden?: bool - include_schema_type_path?: bool - fast_eval?: bool - -schema Decorator: - r""" - Message representing a decorator in KCL. - - - Attributes - ---------- - name : str, optional - Name of the decorator. - - arguments : [str], optional - Arguments for the decorator. - - keywords : {str:str}, optional - Keyword arguments for the decorator as a map with keyword name as key. - - """ - - name?: str - arguments?: [str] - keywords?: {str:str} - -schema Error: - r""" - Message representing an error. - - - Attributes - ---------- - level : str, optional - Level of the error (e.g., "Error", "Warning"). - - code : str, optional - Error code. (e.g., "E1001") - - messages : [Message], optional - List of error messages. - - """ - - level?: str - code?: str - messages?: [Message] - -schema Example: - r""" - Message representing an example in KCL. - - - Attributes - ---------- - summary : str, optional - Short description for the example. - - description : str, optional - Long description for the example. - - value : str, optional - Embedded literal example. - - """ - - summary?: str - description?: str - value?: str - -schema ExecArtifact_Args: - r""" - Message for execute artifact request arguments. - - - Attributes - ---------- - path : str, optional - Path of the artifact. - - exec_args : ExecProgram_Args, optional - Arguments for executing the program. - - """ - - path?: str - exec_args?: ExecProgram_Args - -schema ExecProgram_Args: - r""" - Message for execute program request arguments. - - - Attributes - ---------- - work_dir : str, optional - Working directory. - - k_filename_list : [str], optional - List of KCL filenames. - - k_code_list : [str], optional - List of KCL codes. - - args : [Argument], optional - Arguments for the program. - - overrides : [str], optional - Override configurations. - - disable_yaml_result : bool, optional - Flag to disable YAML result. - - print_override_ast : bool, optional - Flag to print override AST. - - strict_range_check : bool, optional - Flag for strict range check. - - disable_none : bool, optional - Flag to disable none values. - - verbose : int, optional - Verbose level. - - debug : int, optional - Debug level. - - sort_keys : bool, optional - Flag to sort keys in YAML/JSON results. - - external_pkgs : [ExternalPkg], optional - External packages path. - - include_schema_type_path : bool, optional - Flag to include schema type path in results. - - compile_only : bool, optional - Flag to compile only without execution. - - show_hidden : bool, optional - Flag to show hidden attributes. - - path_selector : [str], optional - Path selectors for results. - - fast_eval : bool, optional - Flag for fast evaluation. - - """ - - work_dir?: str - k_filename_list?: [str] - k_code_list?: [str] - args?: [Argument] - overrides?: [str] - disable_yaml_result?: bool - print_override_ast?: bool - strict_range_check?: bool - disable_none?: bool - verbose?: int - debug?: int - sort_keys?: bool - external_pkgs?: [ExternalPkg] - include_schema_type_path?: bool - compile_only?: bool - show_hidden?: bool - path_selector?: [str] - fast_eval?: bool - -schema ExecProgram_Result: - r""" - Message for execute program response. - - - Attributes - ---------- - json_result : str, optional - Result in JSON format. - - yaml_result : str, optional - Result in YAML format. - - log_message : str, optional - Log message from execution. - - err_message : str, optional - Error message from execution. - - """ - - json_result?: str - yaml_result?: str - log_message?: str - err_message?: str - -schema ExternalPkg: - r""" - Message representing an external package for KCL. - kcl main.k -E pkg_name=pkg_path - - - Attributes - ---------- - pkg_name : str, optional - Name of the package. - - pkg_path : str, optional - Path of the package. - - """ - - pkg_name?: str - pkg_path?: str - -schema FormatCode_Args: - r""" - Message for format code request arguments. - - - Attributes - ---------- - source : str, optional - Source code to be formatted. - - """ - - source?: str - -schema FormatCode_Result: - r""" - Message for format code response. - - - Attributes - ---------- - formatted : [int], optional - Formatted code as bytes. - - """ - - formatted?: [int] - -schema FormatPath_Args: - r""" - Message for format file path request arguments. - - - Attributes - ---------- - path : str, optional - Path of the file to format. - - """ - - path?: str - -schema FormatPath_Result: - r""" - Message for format file path response. - - - Attributes - ---------- - changed_paths : [str], optional - List of changed file paths. - - """ - - changed_paths?: [str] - -schema GetSchemaTypeMapping_Args: - r""" - Message for get schema type mapping request arguments. - - - Attributes - ---------- - exec_args : ExecProgram_Args, optional - Arguments for executing the program. - - schema_name : str, optional - Name of the schema. - - """ - - exec_args?: ExecProgram_Args - schema_name?: str - -schema GetSchemaTypeMapping_Result: - r""" - Message for get schema type mapping response. - - - Attributes - ---------- - schema_type_mapping : {str:KclType}, optional - Map of schema type mappings. - - """ - - schema_type_mapping?: {str:KclType} - -schema GetVersion_Args: - r""" - Message for version request arguments. Empty message. - - """ - - -schema GetVersion_Result: - r""" - Message for version response. - - - Attributes - ---------- - version : str, optional - KCL version. - - checksum : str, optional - Checksum of the KCL version. - - git_sha : str, optional - Git Git SHA of the KCL code repo. - - version_info : str, optional - Detailed version information as a string. - - """ - - version?: str - checksum?: str - git_sha?: str - version_info?: str - -schema KclType: - r""" - Message representing a KCL type. - - - Attributes - ---------- - $type : str, optional - Type name (e.g., schema, dict, list, str, int, float, bool, any, union, number_multiplier). - - union_types : [KclType], optional - Union types if applicable. - - default : str, optional - Default value of the type. - - schema_name : str, optional - Name of the schema if applicable. - - schema_doc : str, optional - Documentation for the schema. - - properties : {str:KclType}, optional - Properties of the schema as a map with property name as key. - - required : [str], optional - List of required schema properties. - - key : KclType, optional - Key type if the KclType is a dictionary. - - item : KclType, optional - Item type if the KclType is a list or dictionary. - - line : int, optional - Line number where the type is defined. - - decorators : [Decorator], optional - List of decorators for the schema. - - filename : str, optional - Absolute path of the file where the attribute is located. - - pkg_path : str, optional - Path of the package where the attribute is located. - - description : str, optional - Documentation for the attribute. - - examples : {str:Example}, optional - Map of examples with example name as key. - - base_schema : KclType, optional - Base schema if applicable. - - """ - - $type?: str - union_types?: [KclType] - default?: str - schema_name?: str - schema_doc?: str - properties?: {str:KclType} - required?: [str] - key?: KclType - item?: KclType - line?: int - decorators?: [Decorator] - filename?: str - pkg_path?: str - description?: str - examples?: {str:Example} - base_schema?: KclType - -schema KeyValuePair: - r""" - Message representing a key-value pair. - - - Attributes - ---------- - key : str, optional - Key of the pair. - - value : str, optional - Value of the pair. - - """ - - key?: str - value?: str - -schema LintPath_Args: - r""" - Message for lint file path request arguments. - - - Attributes - ---------- - paths : [str], optional - Paths of the files to lint. - - """ - - paths?: [str] - -schema LintPath_Result: - r""" - Message for lint file path response. - - - Attributes - ---------- - results : [str], optional - List of lint results. - - """ - - results?: [str] - -schema ListDepFiles_Args: - r""" - Message for list dependency files request arguments. - - - Attributes - ---------- - work_dir : str, optional - Working directory. - - use_abs_path : bool, optional - Flag to use absolute paths. - - include_all : bool, optional - Flag to include all files. - - use_fast_parser : bool, optional - Flag to use fast parser. - - """ - - work_dir?: str - use_abs_path?: bool - include_all?: bool - use_fast_parser?: bool - -schema ListDepFiles_Result: - r""" - Message for list dependency files response. - - - Attributes - ---------- - pkgroot : str, optional - Root package path. - - pkgpath : str, optional - Package path. - - files : [str], optional - List of file paths in the package. - - """ - - pkgroot?: str - pkgpath?: str - files?: [str] - -schema ListMethod_Args: - r""" - Message for list method request arguments. Empty message. - - """ - - -schema ListMethod_Result: - r""" - Message for list method response. - - - Attributes - ---------- - method_name_list : [str], optional - List of available method names. - - """ - - method_name_list?: [str] - -schema ListOptions_Result: - r""" - Message for list options response. - - - Attributes - ---------- - options : [OptionHelp], optional - List of available options. - - """ - - options?: [OptionHelp] - -schema ListVariables_Args: - r""" - Message for list variables request arguments. - - - Attributes - ---------- - files : [str], optional - Files to be processed. - - specs : [str], optional - Specifications for variables. - - options : ListVariables_Options, optional - Options for listing variables. - - """ - - files?: [str] - specs?: [str] - options?: ListVariables_Options - -schema ListVariables_Options: - r""" - Message for list variables options. - - - Attributes - ---------- - merge_program : bool, optional - Flag to merge program configuration. - - """ - - merge_program?: bool - -schema ListVariables_Result: - r""" - Message for list variables response. - - - Attributes - ---------- - variables : {str:VariableList}, optional - Map of variable lists by file. - - unsupported_codes : [str], optional - List of unsupported codes. - - parse_errors : [Error], optional - List of parse errors encountered. - - """ - - variables?: {str:VariableList} - unsupported_codes?: [str] - parse_errors?: [Error] - -schema LoadPackage_Args: - r""" - Message for load package request arguments. - - - Attributes - ---------- - parse_args : ParseProgram_Args, optional - Arguments for parsing the program. - - resolve_ast : bool, optional - Flag indicating whether to resolve AST. - - load_builtin : bool, optional - Flag indicating whether to load built-in modules. - - with_ast_index : bool, optional - Flag indicating whether to include AST index. - - """ - - parse_args?: ParseProgram_Args - resolve_ast?: bool - load_builtin?: bool - with_ast_index?: bool - -schema LoadPackage_Result: - r""" - Message for load package response. - - - Attributes - ---------- - program : str, optional - Program Abstract Syntax Tree (AST) in JSON format. - - paths : [str], optional - Returns the files in the order they should be compiled. - - parse_errors : [Error], optional - List of parse errors. - - type_errors : [Error], optional - List of type errors. - - scopes : {str:Scope}, optional - Map of scopes with scope index as key. - - symbols : {str:Symbol}, optional - Map of symbols with symbol index as key. - - node_symbol_map : {str:SymbolIndex}, optional - Map of node-symbol associations with AST index UUID as key. - - symbol_node_map : {str:str}, optional - Map of symbol-node associations with symbol index as key. - - fully_qualified_name_map : {str:SymbolIndex}, optional - Map of fully qualified names with symbol index as key. - - pkg_scope_map : {str:ScopeIndex}, optional - Map of package scope with package path as key. - - """ - - program?: str - paths?: [str] - parse_errors?: [Error] - type_errors?: [Error] - scopes?: {str:Scope} - symbols?: {str:Symbol} - node_symbol_map?: {str:SymbolIndex} - symbol_node_map?: {str:str} - fully_qualified_name_map?: {str:SymbolIndex} - pkg_scope_map?: {str:ScopeIndex} - -schema LoadSettingsFiles_Args: - r""" - Message for load settings files request arguments. - - - Attributes - ---------- - work_dir : str, optional - Working directory. - - files : [str], optional - Setting files to load. - - """ - - work_dir?: str - files?: [str] - -schema LoadSettingsFiles_Result: - r""" - Message for load settings files response. - - - Attributes - ---------- - kcl_cli_configs : CliConfig, optional - KCL CLI configuration. - - kcl_options : [KeyValuePair], optional - List of KCL options as key-value pairs. - - """ - - kcl_cli_configs?: CliConfig - kcl_options?: [KeyValuePair] - -schema MapEntry: - r""" - Message representing a map entry. - - - Attributes - ---------- - key : str, optional - Key of the map entry. - - value : Variable, optional - Value of the map entry. - - """ - - key?: str - value?: Variable - -schema Message: - r""" - Message representing a detailed error message with a position. - - - Attributes - ---------- - msg : str, optional - The error message text. - - pos : Position, optional - The position in the source code where the error occurred. - - """ - - msg?: str - pos?: Position - -schema OptionHelp: - r""" - Message representing a help option. - - - Attributes - ---------- - name : str, optional - Name of the option. - - $type : str, optional - Type of the option. - - required : bool, optional - Flag indicating if the option is required. - - default_value : str, optional - Default value of the option. - - help : str, optional - Help text for the option. - - """ - - name?: str - $type?: str - required?: bool - default_value?: str - help?: str - -schema OverrideFile_Args: - r""" - Message for override file request arguments. - - - Attributes - ---------- - file : str, optional - Path of the file to override. - - specs : [str], optional - List of override specifications. - - import_paths : [str], optional - List of import paths. - - """ - - file?: str - specs?: [str] - import_paths?: [str] - -schema OverrideFile_Result: - r""" - Message for override file response. - - - Attributes - ---------- - result : bool, optional - Result of the override operation. - - parse_errors : [Error], optional - List of parse errors encountered. - - """ - - result?: bool - parse_errors?: [Error] - -schema ParseFile_Args: - r""" - Message for parse file request arguments. - - - Attributes - ---------- - path : str, optional - Path of the file to be parsed. - - source : str, optional - Source code to be parsed. - - external_pkgs : [ExternalPkg], optional - External packages path. - - """ - - path?: str - source?: str - external_pkgs?: [ExternalPkg] - -schema ParseFile_Result: - r""" - Message for parse file response. - - - Attributes - ---------- - ast_json : str, optional - Abstract Syntax Tree (AST) in JSON format. - - deps : [str], optional - File dependency paths. - - errors : [Error], optional - List of parse errors. - - """ - - ast_json?: str - deps?: [str] - errors?: [Error] - -schema ParseProgram_Args: - r""" - Message for parse program request arguments. - - - Attributes - ---------- - paths : [str], optional - Paths of the program files to be parsed. - - sources : [str], optional - Source codes to be parsed. - - external_pkgs : [ExternalPkg], optional - External packages path. - - """ - - paths?: [str] - sources?: [str] - external_pkgs?: [ExternalPkg] - -schema ParseProgram_Result: - r""" - Message for parse program response. - - - Attributes - ---------- - ast_json : str, optional - Abstract Syntax Tree (AST) in JSON format. - - paths : [str], optional - Returns the files in the order they should be compiled. - - errors : [Error], optional - List of parse errors. - - """ - - ast_json?: str - paths?: [str] - errors?: [Error] - -schema Ping_Args: - r""" - Message for ping request arguments. - - - Attributes - ---------- - value : str, optional - Value to be sent in the ping request. - - """ - - value?: str - -schema Ping_Result: - r""" - Message for ping response. - - - Attributes - ---------- - value : str, optional - Value received in the ping response. - - """ - - value?: str - -schema Position: - r""" - Message representing a position in the source code. - - - Attributes - ---------- - line : int, optional - Line number. - - column : int, optional - Column number. - - filename : str, optional - Filename the position refers to. - - """ - - line?: int - column?: int - filename?: str - -schema RenameCode_Args: - r""" - Message for rename code request arguments. - - - Attributes - ---------- - package_root : str, optional - File path to the package root. - - symbol_path : str, optional - Path to the target symbol to be renamed. - - source_codes : {str:str}, optional - Map of source code with filename as key and code as value. - - new_name : str, optional - New name of the symbol. - - """ - - package_root?: str - symbol_path?: str - source_codes?: {str:str} - new_name?: str - -schema RenameCode_Result: - r""" - Message for rename code response. - - - Attributes - ---------- - changed_codes : {str:str}, optional - Map of changed code with filename as key and modified code as value. - - """ - - changed_codes?: {str:str} - -schema Rename_Args: - r""" - Message for rename request arguments. - - - Attributes - ---------- - package_root : str, optional - File path to the package root. - - symbol_path : str, optional - Path to the target symbol to be renamed. - - file_paths : [str], optional - Paths to the source code files. - - new_name : str, optional - New name of the symbol. - - """ - - package_root?: str - symbol_path?: str - file_paths?: [str] - new_name?: str - -schema Rename_Result: - r""" - Message for rename response. - - - Attributes - ---------- - changed_files : [str], optional - List of file paths that got changed. - - """ - - changed_files?: [str] - -schema Scope: - r""" - Message representing a scope in KCL. - - - Attributes - ---------- - kind : str, optional - Type of the scope. - - parent : ScopeIndex, optional - Parent scope. - - owner : SymbolIndex, optional - Owner of the scope. - - children : [ScopeIndex], optional - Children of the scope. - - defs : [SymbolIndex], optional - Definitions in the scope. - - """ - - kind?: str - parent?: ScopeIndex - owner?: SymbolIndex - children?: [ScopeIndex] - defs?: [SymbolIndex] - -schema ScopeIndex: - r""" - Message representing a scope index. - - - Attributes - ---------- - i : int, optional - Index identifier. - - g : int, optional - Global identifier. - - kind : str, optional - Type of the scope. - - """ - - i?: int - g?: int - kind?: str - -schema Symbol: - r""" - Message representing a symbol in KCL. - - - Attributes - ---------- - ty : KclType, optional - Type of the symbol. - - name : str, optional - Name of the symbol. - - owner : SymbolIndex, optional - Owner of the symbol. - - def : SymbolIndex, optional - Definition of the symbol. - - attrs : [SymbolIndex], optional - Attributes of the symbol. - - is_global : bool, optional - Flag indicating if the symbol is global. - - """ - - ty?: KclType - name?: str - owner?: SymbolIndex - def?: SymbolIndex - attrs?: [SymbolIndex] - is_global?: bool - -schema SymbolIndex: - r""" - Message representing a symbol index. - - - Attributes - ---------- - i : int, optional - Index identifier. - - g : int, optional - Global identifier. - - kind : str, optional - Type of the symbol or scope. - - """ - - i?: int - g?: int - kind?: str - -schema TestCaseInfo: - r""" - Message representing information about a single test case. - - - Attributes - ---------- - name : str, optional - Name of the test case. - - error : str, optional - Error message if any. - - duration : int, optional - Duration of the test case in microseconds. - - log_message : str, optional - Log message from the test case. - - """ - - name?: str - error?: str - duration?: int - log_message?: str - -schema Test_Args: - r""" - Message for test request arguments. - - - Attributes - ---------- - exec_args : ExecProgram_Args, optional - Execution program arguments. - - pkg_list : [str], optional - List of KCL package paths to be tested. - - run_regexp : str, optional - Regular expression for filtering tests to run. - - fail_fast : bool, optional - Flag to stop the test run on the first failure. - - """ - - exec_args?: ExecProgram_Args - pkg_list?: [str] - run_regexp?: str - fail_fast?: bool - -schema Test_Result: - r""" - Message for test response. - - - Attributes - ---------- - info : [TestCaseInfo], optional - List of test case information. - - """ - - info?: [TestCaseInfo] - -schema UnimplementedBuiltinServiceServer: - r""" - UnimplementedBuiltinServiceServer can be embedded to have forward compatible implementations. - - """ - - -schema UnimplementedKclvmServiceServer: - r""" - UnimplementedKclvmServiceServer can be embedded to have forward compatible implementations. - - """ - - -schema UpdateDependencies_Args: - r""" - Message for update dependencies request arguments. - - - Attributes - ---------- - manifest_path : str, optional - Path to the manifest file. - - vendor : bool, optional - Flag to vendor dependencies locally. - - """ - - manifest_path?: str - vendor?: bool - -schema UpdateDependencies_Result: - r""" - Message for update dependencies response. - - - Attributes - ---------- - external_pkgs : [ExternalPkg], optional - List of external packages updated. - - """ - - external_pkgs?: [ExternalPkg] - -schema ValidateCode_Args: - r""" - Message for validate code request arguments. - - - Attributes - ---------- - datafile : str, optional - Path to the data file. - - data : str, optional - Data content. - - file : str, optional - Path to the code file. - - code : str, optional - Source code content. - - $schema : str, optional - Name of the schema. - - attribute_name : str, optional - Name of the attribute. - - format : str, optional - Format of the validation (e.g., "json", "yaml"). - - """ - - datafile?: str - data?: str - file?: str - code?: str - $schema?: str - attribute_name?: str - format?: str - -schema ValidateCode_Result: - r""" - Message for validate code response. - - - Attributes - ---------- - success : bool, optional - Flag indicating if validation was successful. - - err_message : str, optional - Error message from validation. - - """ - - success?: bool - err_message?: str - -schema Variable: - r""" - Message representing a variable. - - - Attributes - ---------- - value : str, optional - Value of the variable. - - type_name : str, optional - Type name of the variable. - - op_sym : str, optional - Operation symbol associated with the variable. - - list_items : [Variable], optional - List items if the variable is a list. - - dict_entries : [MapEntry], optional - Dictionary entries if the variable is a dictionary. - - """ - - value?: str - type_name?: str - op_sym?: str - list_items?: [Variable] - dict_entries?: [MapEntry] - -schema VariableList: - r""" - Message representing a list of variables. - - - Attributes - ---------- - variables : [Variable], optional - List of variables. - - """ - - variables?: [Variable] - -schema builtinServiceClient: - r""" - builtinServiceClient - """ - - -schema kclvmServiceClient: - r""" - kclvmServiceClient - """ - - -` - assert2.Equal(t, strings.ReplaceAll(kclCode, "\r\n", "\n"), strings.ReplaceAll(expectedKclCodeFromField, "\r\n", "\n")) -} - -func TestGenKclFromKclGoPackage(t *testing.T) { - var buf bytes.Buffer - opts := &GenKclOptions{ - Mode: ModeGoStruct, - } - err := GenKcl(&buf, "../../kcl", nil, opts) - if err != nil { - log.Fatal(err) - } - kclCode := buf.String() - expectedKclCodeFromField := `""" -This file was generated by the KCL auto-gen tool. DO NOT EDIT. -Editing this file might prove futile when you re-run the KCL auto-gen generate command. -""" - -schema GpyrpcArgument: - r""" - Message representing a key-value argument for KCL. - kcl main.k -D name=value - - - Attributes - ---------- - name : str, optional - Name of the argument. - - value : str, optional - Value of the argument. - - """ - - name?: str - value?: str - -schema GpyrpcDecorator: - r""" - Message representing a decorator in KCL. - - - Attributes - ---------- - name : str, optional - Name of the decorator. - - arguments : [str], optional - Arguments for the decorator. - - keywords : {str:str}, optional - Keyword arguments for the decorator as a map with keyword name as key. - - """ - - name?: str - arguments?: [str] - keywords?: {str:str} - -schema GpyrpcExample: - r""" - Message representing an example in KCL. - - - Attributes - ---------- - summary : str, optional - Short description for the example. - - description : str, optional - Long description for the example. - - value : str, optional - Embedded literal example. - - """ - - summary?: str - description?: str - value?: str - -schema GpyrpcExternalPkg: - r""" - Message representing an external package for KCL. - kcl main.k -E pkg_name=pkg_path - - - Attributes - ---------- - pkg_name : str, optional - Name of the package. - - pkg_path : str, optional - Path of the package. - - """ - - pkg_name?: str - pkg_path?: str - -schema KCLResult: - r""" - KCLResult denotes the result for the Run API. - - """ - - -schema KCLResultList: - r""" - KCLResultList - """ - - -schema KclType: - r""" - Message representing a KCL type. - - - Attributes - ---------- - $type : str, optional - Type name (e.g., schema, dict, list, str, int, float, bool, any, union, number_multiplier). - - union_types : [KclType], optional - Union types if applicable. - - default : str, optional - Default value of the type. - - schema_name : str, optional - Name of the schema if applicable. - - schema_doc : str, optional - Documentation for the schema. - - properties : {str:KclType}, optional - Properties of the schema as a map with property name as key. - - required : [str], optional - List of required schema properties. - - key : KclType, optional - Key type if the KclType is a dictionary. - - item : KclType, optional - Item type if the KclType is a list or dictionary. - - line : int, optional - Line number where the type is defined. - - decorators : [GpyrpcDecorator], optional - List of decorators for the schema. - - filename : str, optional - Absolute path of the file where the attribute is located. - - pkg_path : str, optional - Path of the package where the attribute is located. - - description : str, optional - Documentation for the attribute. - - examples : {str:GpyrpcExample}, optional - Map of examples with example name as key. - - base_schema : KclType, optional - Base schema if applicable. - - """ - - $type?: str - union_types?: [KclType] - default?: str - schema_name?: str - schema_doc?: str - properties?: {str:KclType} - required?: [str] - key?: KclType - item?: KclType - line?: int - decorators?: [GpyrpcDecorator] - filename?: str - pkg_path?: str - description?: str - examples?: {str:GpyrpcExample} - base_schema?: KclType - -schema Option: - r""" - Option - - Attributes - ---------- - work_dir : str, optional - Working directory. - - k_filename_list : [str], optional - List of KCL filenames. - - k_code_list : [str], optional - List of KCL codes. - - args : [GpyrpcArgument], optional - Arguments for the program. - - overrides : [str], optional - Override configurations. - - disable_yaml_result : bool, optional - Flag to disable YAML result. - - print_override_ast : bool, optional - Flag to print override AST. - - strict_range_check : bool, optional - Flag for strict range check. - - disable_none : bool, optional - Flag to disable none values. - - verbose : int, optional - Verbose level. - - debug : int, optional - Debug level. - - sort_keys : bool, optional - Flag to sort keys in YAML/JSON results. - - external_pkgs : [GpyrpcExternalPkg], optional - External packages path. - - include_schema_type_path : bool, optional - Flag to include schema type path in results. - - compile_only : bool, optional - Flag to compile only without execution. - - show_hidden : bool, optional - Flag to show hidden attributes. - - path_selector : [str], optional - Path selectors for results. - - fast_eval : bool, optional - Flag for fast evaluation. - - Err : any, optional - """ - - work_dir?: str - k_filename_list?: [str] - k_code_list?: [str] - args?: [GpyrpcArgument] - overrides?: [str] - disable_yaml_result?: bool - print_override_ast?: bool - strict_range_check?: bool - disable_none?: bool - verbose?: int - debug?: int - sort_keys?: bool - external_pkgs?: [GpyrpcExternalPkg] - include_schema_type_path?: bool - compile_only?: bool - show_hidden?: bool - path_selector?: [str] - fast_eval?: bool - Err?: any - -schema VersionResult: - r""" - VersionResult - - Attributes - ---------- - version : str, optional - KCL version. - - checksum : str, optional - Checksum of the KCL version. - - git_sha : str, optional - Git Git SHA of the KCL code repo. - - version_info : str, optional - Detailed version information as a string. - - """ - - version?: str - checksum?: str - git_sha?: str - version_info?: str - -schema typeAttributeHook: - r""" - typeAttributeHook - """ - - -` - assert2.Equal(t, strings.ReplaceAll(kclCode, "\r\n", "\n"), strings.ReplaceAll(expectedKclCodeFromField, "\r\n", "\n")) -} - -func TestGenKclFromKclGoLoaderPackage(t *testing.T) { - var buf bytes.Buffer - opts := &GenKclOptions{ - Mode: ModeGoStruct, - } - err := GenKcl(&buf, "../../loader", nil, opts) - if err != nil { - log.Fatal(err) - } - kclCode := buf.String() - expectedKclCodeFromField := `""" -This file was generated by the KCL auto-gen tool. DO NOT EDIT. -Editing this file might prove futile when you re-run the KCL auto-gen generate command. -""" - -schema GpyrpcDecorator: - r""" - Message representing a decorator in KCL. - - - Attributes - ---------- - name : str, optional - Name of the decorator. - - arguments : [str], optional - Arguments for the decorator. - - keywords : {str:str}, optional - Keyword arguments for the decorator as a map with keyword name as key. - - """ - - name?: str - arguments?: [str] - keywords?: {str:str} - -schema GpyrpcError: - r""" - Message representing an error. - - - Attributes - ---------- - level : str, optional - Level of the error (e.g., "Error", "Warning"). - - code : str, optional - Error code. (e.g., "E1001") - - messages : [GpyrpcMessage], optional - List of error messages. - - """ - - level?: str - code?: str - messages?: [GpyrpcMessage] - -schema GpyrpcExample: - r""" - Message representing an example in KCL. - - - Attributes - ---------- - summary : str, optional - Short description for the example. - - description : str, optional - Long description for the example. - - value : str, optional - Embedded literal example. - - """ - - summary?: str - description?: str - value?: str - -schema GpyrpcExternalPkg: - r""" - Message representing an external package for KCL. - kcl main.k -E pkg_name=pkg_path - - - Attributes - ---------- - pkg_name : str, optional - Name of the package. - - pkg_path : str, optional - Path of the package. - - """ - - pkg_name?: str - pkg_path?: str - -schema GpyrpcKclType: - r""" - Message representing a KCL type. - - - Attributes - ---------- - $type : str, optional - Type name (e.g., schema, dict, list, str, int, float, bool, any, union, number_multiplier). - - union_types : [GpyrpcKclType], optional - Union types if applicable. - - default : str, optional - Default value of the type. - - schema_name : str, optional - Name of the schema if applicable. - - schema_doc : str, optional - Documentation for the schema. - - properties : {str:GpyrpcKclType}, optional - Properties of the schema as a map with property name as key. - - required : [str], optional - List of required schema properties. - - key : GpyrpcKclType, optional - Key type if the KclType is a dictionary. - - item : GpyrpcKclType, optional - Item type if the KclType is a list or dictionary. - - line : int, optional - Line number where the type is defined. - - decorators : [GpyrpcDecorator], optional - List of decorators for the schema. - - filename : str, optional - Absolute path of the file where the attribute is located. - - pkg_path : str, optional - Path of the package where the attribute is located. - - description : str, optional - Documentation for the attribute. - - examples : {str:GpyrpcExample}, optional - Map of examples with example name as key. - - base_schema : GpyrpcKclType, optional - Base schema if applicable. - - """ - - $type?: str - union_types?: [GpyrpcKclType] - default?: str - schema_name?: str - schema_doc?: str - properties?: {str:GpyrpcKclType} - required?: [str] - key?: GpyrpcKclType - item?: GpyrpcKclType - line?: int - decorators?: [GpyrpcDecorator] - filename?: str - pkg_path?: str - description?: str - examples?: {str:GpyrpcExample} - base_schema?: GpyrpcKclType - -schema GpyrpcListVariablesOptions: - r""" - Message for list variables options. - - - Attributes - ---------- - merge_program : bool, optional - Flag to merge program configuration. - - """ - - merge_program?: bool - -schema GpyrpcMapEntry: - r""" - Message representing a map entry. - - - Attributes - ---------- - key : str, optional - Key of the map entry. - - value : GpyrpcVariable, optional - Value of the map entry. - - """ - - key?: str - value?: GpyrpcVariable - -schema GpyrpcMessage: - r""" - Message representing a detailed error message with a position. - - - Attributes - ---------- - msg : str, optional - The error message text. - - pos : GpyrpcPosition, optional - The position in the source code where the error occurred. - - """ - - msg?: str - pos?: GpyrpcPosition - -schema GpyrpcOptionHelp: - r""" - Message representing a help option. - - - Attributes - ---------- - name : str, optional - Name of the option. - - $type : str, optional - Type of the option. - - required : bool, optional - Flag indicating if the option is required. - - default_value : str, optional - Default value of the option. - - help : str, optional - Help text for the option. - - """ - - name?: str - $type?: str - required?: bool - default_value?: str - help?: str - -schema GpyrpcPosition: - r""" - Message representing a position in the source code. - - - Attributes - ---------- - line : int, optional - Line number. - - column : int, optional - Column number. - - filename : str, optional - Filename the position refers to. - - """ - - line?: int - column?: int - filename?: str - -schema GpyrpcScope: - r""" - Message representing a scope in KCL. - - - Attributes - ---------- - kind : str, optional - Type of the scope. - - parent : GpyrpcScopeIndex, optional - Parent scope. - - owner : GpyrpcSymbolIndex, optional - Owner of the scope. - - children : [GpyrpcScopeIndex], optional - Children of the scope. - - defs : [GpyrpcSymbolIndex], optional - Definitions in the scope. - - """ - - kind?: str - parent?: GpyrpcScopeIndex - owner?: GpyrpcSymbolIndex - children?: [GpyrpcScopeIndex] - defs?: [GpyrpcSymbolIndex] - -schema GpyrpcScopeIndex: - r""" - Message representing a scope index. - - - Attributes - ---------- - i : int, optional - Index identifier. - - g : int, optional - Global identifier. - - kind : str, optional - Type of the scope. - - """ - - i?: int - g?: int - kind?: str - -schema GpyrpcSymbol: - r""" - Message representing a symbol in KCL. - - - Attributes - ---------- - ty : GpyrpcKclType, optional - Type of the symbol. - - name : str, optional - Name of the symbol. - - owner : GpyrpcSymbolIndex, optional - Owner of the symbol. - - def : GpyrpcSymbolIndex, optional - Definition of the symbol. - - attrs : [GpyrpcSymbolIndex], optional - Attributes of the symbol. - - is_global : bool, optional - Flag indicating if the symbol is global. - - """ - - ty?: GpyrpcKclType - name?: str - owner?: GpyrpcSymbolIndex - def?: GpyrpcSymbolIndex - attrs?: [GpyrpcSymbolIndex] - is_global?: bool - -schema GpyrpcSymbolIndex: - r""" - Message representing a symbol index. - - - Attributes - ---------- - i : int, optional - Index identifier. - - g : int, optional - Global identifier. - - kind : str, optional - Type of the symbol or scope. - - """ - - i?: int - g?: int - kind?: str - -schema GpyrpcVariable: - r""" - Message representing a variable. - - - Attributes - ---------- - value : str, optional - Value of the variable. - - type_name : str, optional - Type name of the variable. - - op_sym : str, optional - Operation symbol associated with the variable. - - list_items : [GpyrpcVariable], optional - List items if the variable is a list. - - dict_entries : [GpyrpcMapEntry], optional - Dictionary entries if the variable is a dictionary. - - """ - - value?: str - type_name?: str - op_sym?: str - list_items?: [GpyrpcVariable] - dict_entries?: [GpyrpcMapEntry] - -schema GpyrpcVariableList: - r""" - Message representing a list of variables. - - - Attributes - ---------- - variables : [GpyrpcVariable], optional - List of variables. - - """ - - variables?: [GpyrpcVariable] - -schema ListOptionsArgs: - r""" - ListOptionsArgs - - Attributes - ---------- - paths : [str], optional - Paths of the program files to be parsed. - - sources : [str], optional - Source codes to be parsed. - - external_pkgs : [GpyrpcExternalPkg], optional - External packages path. - - """ - - paths?: [str] - sources?: [str] - external_pkgs?: [GpyrpcExternalPkg] - -schema ListOptionsResult: - r""" - ListOptionsResult - - Attributes - ---------- - options : [GpyrpcOptionHelp], optional - List of available options. - - """ - - options?: [GpyrpcOptionHelp] - -schema ListVariablesArgs: - r""" - ListVariablesArgs - - Attributes - ---------- - files : [str], optional - Files to be processed. - - specs : [str], optional - Specifications for variables. - - options : GpyrpcListVariablesOptions, optional - Options for listing variables. - - """ - - files?: [str] - specs?: [str] - options?: GpyrpcListVariablesOptions - -schema ListVariablesResult: - r""" - ListVariablesResult - - Attributes - ---------- - variables : {str:GpyrpcVariableList}, optional - Map of variable lists by file. - - unsupported_codes : [str], optional - List of unsupported codes. - - parse_errors : [GpyrpcError], optional - List of parse errors encountered. - - """ - - variables?: {str:GpyrpcVariableList} - unsupported_codes?: [str] - parse_errors?: [GpyrpcError] - -schema LoadPackageArgs: - r""" - LoadPackageArgs - - Attributes - ---------- - parse_args : ParseProgram_Args, optional - Arguments for parsing the program. - - resolve_ast : bool, optional - Flag indicating whether to resolve AST. - - load_builtin : bool, optional - Flag indicating whether to load built-in modules. - - with_ast_index : bool, optional - Flag indicating whether to include AST index. - - """ - - parse_args?: ParseProgram_Args - resolve_ast?: bool - load_builtin?: bool - with_ast_index?: bool - -schema LoadPackageResult: - r""" - LoadPackageResult - - Attributes - ---------- - program : str, optional - Program Abstract Syntax Tree (AST) in JSON format. - - paths : [str], optional - Returns the files in the order they should be compiled. - - parse_errors : [GpyrpcError], optional - List of parse errors. - - type_errors : [GpyrpcError], optional - List of type errors. - - scopes : {str:GpyrpcScope}, optional - Map of scopes with scope index as key. - - symbols : {str:GpyrpcSymbol}, optional - Map of symbols with symbol index as key. - - node_symbol_map : {str:GpyrpcSymbolIndex}, optional - Map of node-symbol associations with AST index UUID as key. - - symbol_node_map : {str:str}, optional - Map of symbol-node associations with symbol index as key. - - fully_qualified_name_map : {str:GpyrpcSymbolIndex}, optional - Map of fully qualified names with symbol index as key. - - pkg_scope_map : {str:GpyrpcScopeIndex}, optional - Map of package scope with package path as key. - - """ - - program?: str - paths?: [str] - parse_errors?: [GpyrpcError] - type_errors?: [GpyrpcError] - scopes?: {str:GpyrpcScope} - symbols?: {str:GpyrpcSymbol} - node_symbol_map?: {str:GpyrpcSymbolIndex} - symbol_node_map?: {str:str} - fully_qualified_name_map?: {str:GpyrpcSymbolIndex} - pkg_scope_map?: {str:GpyrpcScopeIndex} - -` - assert2.Equal(t, strings.ReplaceAll(kclCode, "\r\n", "\n"), strings.ReplaceAll(expectedKclCodeFromField, "\r\n", "\n")) -}