@@ -216,3 +216,51 @@ def test_barcode_readability_eci(self):
216216
217217if __name__ == '__main__' :
218218 unittest .main (verbosity = 2 )
219+
220+
221+ # ---------------------------------------------------------------------------
222+ # ECI roundtrip tests (pytest-style)
223+ # Verify that ECI FLG(n) tokens are correctly prepended to the sequence and
224+ # that AztecCode encodes non-Latin payloads without error.
225+ # ---------------------------------------------------------------------------
226+
227+ def test_eci_dict_contains_standard_charsets () -> None :
228+ """encoding_to_eci maps well-known charsets to their ISO 24778 ECI values."""
229+ assert encoding_to_eci ["utf-8" ] == 26
230+ assert encoding_to_eci ["iso8859-1" ] == 1
231+ assert encoding_to_eci ["iso8859-8" ] == 10
232+ assert encoding_to_eci ["shift_jis" ] == 20
233+
234+
235+ def test_eci_sequence_starts_with_flg_punct_for_utf8 () -> None :
236+ """find_optimal_sequence with utf-8 encoding prepends FLG(2) + ECI value 26."""
237+ seq = find_optimal_sequence ("hello" , encoding = "utf-8" )
238+ assert seq [0 ] is Shift .PUNCT , "First element must be Shift.PUNCT for FLG preamble"
239+ assert seq [1 ] is Misc .FLG , "Second element must be Misc.FLG"
240+ assert seq [2 ] == 2 , "FLG count must be 2 (len of '26')"
241+ assert seq [3 ] == 26 , "ECI value for utf-8 must be 26"
242+
243+
244+ def test_eci_sequence_single_digit_eci_value () -> None :
245+ """iso8859-1 (ECI=1) produces a single-digit FLG count of 1."""
246+ seq = find_optimal_sequence ("hello" , encoding = "iso8859-1" )
247+ assert seq [0 ] is Shift .PUNCT
248+ assert seq [1 ] is Misc .FLG
249+ assert seq [2 ] == 1 , "FLG count must be 1 for single-digit ECI value"
250+ assert seq [3 ] == 1 , "ECI value for iso8859-1 must be 1"
251+
252+
253+ def test_aztec_code_utf8_non_ascii_encodes_without_error () -> None :
254+ """AztecCode encodes a UTF-8 payload containing non-ASCII characters."""
255+ payload = "The price is \u20ac 4" # € is U+20AC, not in iso8859-1
256+ code = AztecCode (payload , encoding = "utf-8" )
257+ assert code is not None
258+ assert code .size >= 15
259+
260+
261+ def test_aztec_code_iso8859_8_encodes_without_error () -> None :
262+ """AztecCode encodes a Hebrew payload via iso8859-8 ECI."""
263+ payload = "\u05d0 \u05d1 \u05d2 " # alef, bet, gimel (Unicode Hebrew, iso8859-8 encodable)
264+ code = AztecCode (payload , encoding = "iso8859-8" )
265+ assert code is not None
266+ assert code .size >= 15
0 commit comments