@@ -443,3 +443,152 @@ func TestStringWithSingleBacktickValue(t *testing.T) {
443
443
fmt .Println (string (output ))
444
444
}
445
445
}
446
+
447
+ // TestNewGeneratorWithConfig tests the NewGeneratorWithConfig constructor
448
+ func TestNewGeneratorWithConfig (t * testing.T ) {
449
+ config := GeneratorConfig {
450
+ NoPrefix : true ,
451
+ LowercaseLookup : true ,
452
+ Marshal : true ,
453
+ SQL : true ,
454
+ SQLInt : true ,
455
+ JSONPkg : "custom/json" ,
456
+ Prefix : "TestPrefix" ,
457
+ BuildTags : []string {"tag1" , "tag2" },
458
+ NoComments : true ,
459
+ Values : true ,
460
+ }
461
+
462
+ g := NewGeneratorWithConfig (config )
463
+
464
+ assert .NotNil (t , g )
465
+ assert .Equal (t , config .NoPrefix , g .NoPrefix )
466
+ assert .Equal (t , config .LowercaseLookup , g .LowercaseLookup )
467
+ assert .Equal (t , config .Marshal , g .Marshal )
468
+ assert .Equal (t , config .SQL , g .SQL )
469
+ assert .Equal (t , config .SQLInt , g .SQLInt )
470
+ assert .Equal (t , config .JSONPkg , g .JSONPkg )
471
+ assert .Equal (t , config .Prefix , g .Prefix )
472
+ assert .Equal (t , config .BuildTags , g .BuildTags )
473
+ assert .Equal (t , config .NoComments , g .NoComments )
474
+ assert .Equal (t , config .Values , g .Values )
475
+
476
+ // Test default values
477
+ assert .Equal (t , "-" , g .Version )
478
+ assert .Equal (t , "-" , g .Revision )
479
+ assert .Equal (t , "-" , g .BuildDate )
480
+ assert .Equal (t , "-" , g .BuiltBy )
481
+ assert .NotNil (t , g .knownTemplates )
482
+ assert .NotNil (t , g .t )
483
+ assert .NotNil (t , g .fileSet )
484
+ assert .NotNil (t , g .userTemplateNames )
485
+ }
486
+
487
+ // TestNewGeneratorConfig tests the NewGeneratorConfig constructor
488
+ func TestNewGeneratorConfig (t * testing.T ) {
489
+ config := NewGeneratorConfig ()
490
+
491
+ assert .NotNil (t , config )
492
+ assert .False (t , config .NoPrefix )
493
+ assert .NotNil (t , config .ReplacementNames )
494
+ assert .Equal (t , "encoding/json" , config .JSONPkg )
495
+ assert .Empty (t , config .ReplacementNames )
496
+ }
497
+
498
+ // TestWithSQLInt tests the WithSQLInt option
499
+ func TestWithSQLInt (t * testing.T ) {
500
+ config := & GeneratorConfig {}
501
+ option := WithSQLInt ()
502
+
503
+ assert .False (t , config .SQLInt )
504
+ option (config )
505
+ assert .True (t , config .SQLInt )
506
+ }
507
+
508
+ // TestWithValues tests the WithValues option
509
+ func TestWithValues (t * testing.T ) {
510
+ config := & GeneratorConfig {}
511
+ option := WithValues ()
512
+
513
+ assert .False (t , config .Values )
514
+ option (config )
515
+ assert .True (t , config .Values )
516
+ }
517
+
518
+ // TestWithJsonPkg tests the WithJsonPkg option
519
+ func TestWithJsonPkg (t * testing.T ) {
520
+ config := & GeneratorConfig {}
521
+ testPkg := "custom/json/package"
522
+ option := WithJsonPkg (testPkg )
523
+
524
+ assert .Empty (t , config .JSONPkg )
525
+ option (config )
526
+ assert .Equal (t , testPkg , config .JSONPkg )
527
+ }
528
+
529
+ // TestWithNoComments tests the WithNoComments option
530
+ func TestWithNoComments (t * testing.T ) {
531
+ config := & GeneratorConfig {}
532
+ option := WithNoComments ()
533
+
534
+ assert .False (t , config .NoComments )
535
+ option (config )
536
+ assert .True (t , config .NoComments )
537
+ }
538
+
539
+ // TestWithBuildTags tests the WithBuildTags option
540
+ func TestWithBuildTags (t * testing.T ) {
541
+ config := & GeneratorConfig {}
542
+ testTags := []string {"tag1" , "tag2" , "tag3" }
543
+ option := WithBuildTags (testTags ... )
544
+
545
+ assert .Empty (t , config .BuildTags )
546
+ option (config )
547
+ assert .Equal (t , testTags , config .BuildTags )
548
+
549
+ // Test appending more tags
550
+ moreTags := []string {"tag4" , "tag5" }
551
+ option2 := WithBuildTags (moreTags ... )
552
+ option2 (config )
553
+ expectedTags := append (testTags , moreTags ... )
554
+ assert .Equal (t , expectedTags , config .BuildTags )
555
+ }
556
+
557
+ // TestAllOptionsIntegration tests using multiple options together
558
+ func TestAllOptionsIntegration (t * testing.T ) {
559
+ g := NewGenerator (
560
+ WithSQLInt (),
561
+ WithValues (),
562
+ WithJsonPkg ("custom/json" ),
563
+ WithNoComments (),
564
+ WithBuildTags ("integration" , "test" ),
565
+ )
566
+
567
+ assert .True (t , g .SQLInt )
568
+ assert .True (t , g .Values )
569
+ assert .Equal (t , "custom/json" , g .JSONPkg )
570
+ assert .True (t , g .NoComments )
571
+ assert .Equal (t , []string {"integration" , "test" }, g .BuildTags )
572
+ }
573
+
574
+ // TestGeneratorConfigWithTemplates tests NewGeneratorWithConfig with templates
575
+ func TestGeneratorConfigWithTemplates (t * testing.T ) {
576
+ config := GeneratorConfig {
577
+ // Use empty template file names to avoid file not found errors
578
+ TemplateFileNames : []string {},
579
+ }
580
+
581
+ g := NewGeneratorWithConfig (config )
582
+ assert .NotNil (t , g )
583
+ assert .Equal (t , config .TemplateFileNames , g .TemplateFileNames )
584
+
585
+ // Test with non-empty but valid scenario - no actual templates needed for coverage
586
+ config2 := GeneratorConfig {
587
+ NoPrefix : true ,
588
+ Values : true ,
589
+ }
590
+ g2 := NewGeneratorWithConfig (config2 )
591
+ assert .NotNil (t , g2 )
592
+ assert .True (t , g2 .NoPrefix )
593
+ assert .True (t , g2 .Values )
594
+ }
0 commit comments