forked from kcl-lang/kcl-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenkcl_gostruct_test.go
2381 lines (1657 loc) · 44.9 KB
/
genkcl_gostruct_test.go
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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
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.