44using AwesomeAssertions ;
55using ImperatorToCK3 . CK3 . Religions ;
66using ImperatorToCK3 . CK3 . Titles ;
7+ using System ;
8+ using System . IO ;
9+ using System . Linq ;
710using System . Text . RegularExpressions ;
811using Xunit ;
912
@@ -41,4 +44,149 @@ public void ReligionAttributesAreReadAndSerialized() {
4144 "doctrine=doctrine_gender_male_dominated"
4245 ) ;
4346 }
47+
48+ [ Fact ]
49+ public void DoctrinesInSameCategoryAreLimitedToNumberOfPicks ( ) {
50+ // Arrange: Create a doctrine category with only 2 picks allowed
51+ var categoryReader = new BufferedReader (
52+ "number_of_picks = 2\n " +
53+ "doctrine_head_1 = {}\n " +
54+ "doctrine_head_2 = {}\n " +
55+ "doctrine_head_3 = {}\n " +
56+ "doctrine_head_4 = {}\n "
57+ ) ;
58+ var religions = new ReligionCollection ( new Title . LandedTitles ( ) ) ;
59+ religions . DoctrineCategories . AddOrReplace ( new DoctrineCategory ( "head_category" , categoryReader ) ) ;
60+
61+ // Act: Create a religion with 4 doctrines from the same category (exceeds limit)
62+ var reader = new BufferedReader ( @"{
63+ doctrine = doctrine_head_1
64+ doctrine = doctrine_head_2
65+ doctrine = doctrine_head_3
66+ doctrine = doctrine_head_4
67+ }" ) ;
68+ var religion = new Religion ( "test_religion" , reader , religions , new ColorFactory ( ) ) ;
69+
70+ // Assert: Should keep only the last 2 doctrines (doctrine_head_3 and doctrine_head_4)
71+ Assert . Equal ( 2 , religion . DoctrineIds . Count ) ;
72+ Assert . Contains ( "doctrine_head_3" , religion . DoctrineIds ) ;
73+ Assert . Contains ( "doctrine_head_4" , religion . DoctrineIds ) ;
74+ Assert . DoesNotContain ( "doctrine_head_1" , religion . DoctrineIds ) ;
75+ Assert . DoesNotContain ( "doctrine_head_2" , religion . DoctrineIds ) ;
76+ }
77+
78+ [ Fact ]
79+ public void InvalidColorInFaithLogsWarning ( ) {
80+ // Arrange: Create a religion with a faith that has an invalid color format.
81+ var reader = new BufferedReader ( @"{
82+ faiths = {
83+ test_faith = {
84+ color = hex #345345345
85+ }
86+ }
87+ }" ) ;
88+ var religions = new ReligionCollection ( new Title . LandedTitles ( ) ) ;
89+
90+ // Act: Capture log output during religion creation.
91+ var logWriter = new StringWriter ( ) ;
92+ Console . SetOut ( logWriter ) ;
93+ var religion = new Religion ( "test_religion" , reader , religions , new ColorFactory ( ) ) ;
94+
95+ // Assert: Faith should still be created despite the invalid color.
96+ Assert . Single ( religion . Faiths ) ;
97+ var faith = religion . Faiths . First ( f => f . Id == "test_faith" ) ;
98+ Assert . Null ( faith . Color ) ;
99+
100+ // Assert: Warning should be logged.
101+ var logOutput = logWriter . ToString ( ) ;
102+ logOutput . Should ( ) . Contain ( "Found invalid color" ) ;
103+ }
104+
105+ [ Fact ]
106+ public void ReligiousHeadIsSetWhenNotNone ( ) {
107+ // Arrange: Create a religion with a faith that has a religious head title
108+ var reader = new BufferedReader ( @"{
109+ faiths = {
110+ test_faith = {
111+ religious_head = k_papal_state
112+ }
113+ }
114+ }" ) ;
115+ var religions = new ReligionCollection ( new Title . LandedTitles ( ) ) ;
116+ var religion = new Religion ( "test_religion" , reader , religions , new ColorFactory ( ) ) ;
117+
118+ // Assert: Faith should be created with the religious head title
119+ Assert . Single ( religion . Faiths ) ;
120+ var faith = religion . Faiths . First ( f => f . Id == "test_faith" ) ;
121+ Assert . Equal ( "k_papal_state" , faith . ReligiousHeadTitleId ) ;
122+ }
123+
124+ [ Fact ]
125+ public void ReligiousHeadIsNotSetWhenNone ( ) {
126+ // Arrange: Create a religion with a faith that has religious_head = none
127+ var reader = new BufferedReader ( @"{
128+ faiths = {
129+ test_faith = {
130+ religious_head = none
131+ }
132+ }
133+ }" ) ;
134+ var religions = new ReligionCollection ( new Title . LandedTitles ( ) ) ;
135+ var religion = new Religion ( "test_religion" , reader , religions , new ColorFactory ( ) ) ;
136+
137+ // Assert: Faith should be created but ReligiousHeadTitleId should be null
138+ Assert . Single ( religion . Faiths ) ;
139+ var faith = religion . Faiths . First ( f => f . Id == "test_faith" ) ;
140+ Assert . Null ( faith . ReligiousHeadTitleId ) ;
141+ }
142+
143+ [ Fact ]
144+ public void ReligiousHeadIsSerializedWhenSet ( ) {
145+ // Arrange: Create a religion with a faith that has a religious head title
146+ var reader = new BufferedReader ( @"{
147+ faiths = {
148+ test_faith = {
149+ religious_head = k_papal_state
150+ }
151+ }
152+ }" ) ;
153+ var religions = new ReligionCollection ( new Title . LandedTitles ( ) ) ;
154+ var religion = new Religion ( "test_religion" , reader , religions , new ColorFactory ( ) ) ;
155+
156+ // Act: Serialize the religion
157+ var religionStr = PDXSerializer . Serialize ( religion ) ;
158+
159+ // Assert: The religious head should be serialized in the faith
160+ religionStr . Should ( ) . Contain ( "religious_head=k_papal_state" ) ;
161+ }
162+
163+ [ Fact ]
164+ public void FaithAttributesAreParsedAndStored ( ) {
165+ // Arrange: Create a religion with a faith that has custom attributes (not specially handled keywords)
166+ var reader = new BufferedReader ( @"{
167+ faiths = {
168+ test_faith = {
169+ icon = custom_faith_icon
170+ localization = test_faith_loc
171+ custom_modifier = some_value
172+ special_mechanic = yes
173+ }
174+ }
175+ }" ) ;
176+ var religions = new ReligionCollection ( new Title . LandedTitles ( ) ) ;
177+ var religion = new Religion ( "test_religion" , reader , religions , new ColorFactory ( ) ) ;
178+
179+ // Assert: Faith should be created and attributes should be accessible through serialization
180+ Assert . Single ( religion . Faiths ) ;
181+ var faith = religion . Faiths . First ( f => f . Id == "test_faith" ) ;
182+
183+ // Serialize to verify attributes are stored and output correctly
184+ var faithStr = PDXSerializer . Serialize ( faith ) ;
185+ faithStr . Should ( ) . ContainAll (
186+ "icon = custom_faith_icon" ,
187+ "localization = test_faith_loc" ,
188+ "custom_modifier = some_value" ,
189+ "special_mechanic = yes"
190+ ) ;
191+ }
44192}
0 commit comments