From 4dc3bc7f1aa0fd1e854bcd5e9b076d8e37678b45 Mon Sep 17 00:00:00 2001 From: saurabh Date: Mon, 20 Oct 2025 09:44:02 +0530 Subject: [PATCH 1/3] Add test for UTF-8 txtar encoding --- .idea/workspace.xml | 149 ++++++++++++++++++++++++++++++++++++++++++ txtar/archive_test.go | 27 ++++++++ 2 files changed, 176 insertions(+) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000000..b1bc66250f4 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1760862636057 + + + + + + + + + + + + + + true + + \ No newline at end of file diff --git a/txtar/archive_test.go b/txtar/archive_test.go index 18d61465d7a..ac7dbb5199e 100644 --- a/txtar/archive_test.go +++ b/txtar/archive_test.go @@ -117,3 +117,30 @@ func shortArchive(a *Archive) string { } return buf.String() } + +func TestParseWithCommentAndUTF8(t *testing.T) { + data := []byte(`# This is a test comment +-- hello.txt -- +Hello +-- unicode.txt -- +Go语言 +`) + + ar := Parse(data) + + if len(ar.Files) != 2 { + t.Fatalf("expected 2 files, got %d", len(ar.Files)) + } + + if string(ar.Comment) != "# This is a test comment\n" { + t.Errorf("unexpected comment: %q", ar.Comment) + } + + if ar.Files[1].Name != "unicode.txt" { + t.Errorf("expected unicode.txt, got %s", ar.Files[1].Name) + } + + if string(ar.Files[1].Data) != "Go语言\n" { + t.Errorf("unexpected data for unicode.txt: %q", ar.Files[1].Data) + } +} From c276b0bb05db9650be7406e9086755cff8e52d32 Mon Sep 17 00:00:00 2001 From: Saurabh <74585600+saurabhgame@users.noreply.github.com> Date: Mon, 20 Oct 2025 09:48:53 +0530 Subject: [PATCH 2/3] reverted unnecessary files --- .idea/workspace.xml | 149 -------------------------------------------- 1 file changed, 149 deletions(-) delete mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index b1bc66250f4..00000000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1760862636057 - - - - - - - - - - - - - - true - - \ No newline at end of file From 920f68450aa0705832aa9abafc0b6c68a332e126 Mon Sep 17 00:00:00 2001 From: saurabh Date: Sat, 25 Oct 2025 21:13:45 +0530 Subject: [PATCH 3/3] txtar: move UTF-8 test into TestParse table --- txtar/archive_test.go | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/txtar/archive_test.go b/txtar/archive_test.go index ac7dbb5199e..e05fd5f748e 100644 --- a/txtar/archive_test.go +++ b/txtar/archive_test.go @@ -52,6 +52,22 @@ some content Files: []File{{"file", []byte("data\r\n")}}, }, }, + { + name: "utf8 and comment", + text: `# This is a test comment +-- hello.txt -- +Hello +-- unicode.txt -- +Go语言 +`, + parsed: &Archive{ + Comment: []byte("# This is a test comment\n"), + Files: []File{ + {"hello.txt", []byte("Hello\n")}, + {"unicode.txt", []byte("Go语言\n")}, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -117,30 +133,3 @@ func shortArchive(a *Archive) string { } return buf.String() } - -func TestParseWithCommentAndUTF8(t *testing.T) { - data := []byte(`# This is a test comment --- hello.txt -- -Hello --- unicode.txt -- -Go语言 -`) - - ar := Parse(data) - - if len(ar.Files) != 2 { - t.Fatalf("expected 2 files, got %d", len(ar.Files)) - } - - if string(ar.Comment) != "# This is a test comment\n" { - t.Errorf("unexpected comment: %q", ar.Comment) - } - - if ar.Files[1].Name != "unicode.txt" { - t.Errorf("expected unicode.txt, got %s", ar.Files[1].Name) - } - - if string(ar.Files[1].Data) != "Go语言\n" { - t.Errorf("unexpected data for unicode.txt: %q", ar.Files[1].Data) - } -}