From c22d99d2ea0d2a7a2b46192cbd5d18c91c052be1 Mon Sep 17 00:00:00 2001 From: sun128764 Date: Thu, 21 Sep 2023 19:22:42 +0800 Subject: [PATCH] test: add parser exception test --- AssParser.Test/AssParser.Test.csproj | 3 +++ AssParser.Test/AssParserTest/AssParserTest.cs | 18 +++++++++++++- AssParser.Test/AssParserTest/event_23.ass | 24 +++++++++++++++++++ AssParser.Test/AssParserTest/format_14.ass | 24 +++++++++++++++++++ AssParser.Test/AssParserTest/format_19.ass | 24 +++++++++++++++++++ AssParser.Test/AssParserTest/style_15.ass | 24 +++++++++++++++++++ 6 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 AssParser.Test/AssParserTest/event_23.ass create mode 100644 AssParser.Test/AssParserTest/format_14.ass create mode 100644 AssParser.Test/AssParserTest/format_19.ass create mode 100644 AssParser.Test/AssParserTest/style_15.ass diff --git a/AssParser.Test/AssParser.Test.csproj b/AssParser.Test/AssParser.Test.csproj index 4eee39e..ad3abb9 100644 --- a/AssParser.Test/AssParser.Test.csproj +++ b/AssParser.Test/AssParser.Test.csproj @@ -39,6 +39,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/AssParser.Test/AssParserTest/AssParserTest.cs b/AssParser.Test/AssParserTest/AssParserTest.cs index c202cee..44a5114 100644 --- a/AssParser.Test/AssParserTest/AssParserTest.cs +++ b/AssParser.Test/AssParserTest/AssParserTest.cs @@ -1,4 +1,5 @@ -using System; +using AssParser.Lib; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -38,5 +39,20 @@ public void ToString_ShouldBe_Same(string file) //Assert Assert.Equal(source.Replace("\r\n", "\n").Replace("\n", "\r\n"), res.Replace("\r\n", "\n").Replace("\n", "\r\n")); } + [Fact] + public async void AssParser_ShouldThrow_InvalidStyle() + { + //Arrange + var path = Path.Combine("AssParserTest", "format_14.ass"); + using var sr = new StreamReader(File.OpenRead(path)); + + //Act + var act = () => Lib.AssParser.ParseAssFile(sr); + + //Assert + var exception = await Assert.ThrowsAsync(act); + Assert.Equal(14, exception?.LineCount); + Assert.Equal(AssParserErrorType.InvalidStyleLine, exception?.ErrorType); + } } } diff --git a/AssParser.Test/AssParserTest/event_23.ass b/AssParser.Test/AssParserTest/event_23.ass new file mode 100644 index 0000000..35f45a8 --- /dev/null +++ b/AssParser.Test/AssParserTest/event_23.ass @@ -0,0 +1,24 @@ +[Script Info] +; Script generated by Aegisub 0-mod-d5c132a +; http://www.aegisub.org/ +Comment: [Processed by 繁化姬 dict-7ac3466c-r881 @ 2019/08/22 15:37:24 | https://zhconvert.org +Title: [Nekomoe kissaten] Uma Musume [14][BDRip].JPSC +ScriptType: v4.00+ +WrapStyle: 2 +ScaledBorderAndShadow: yes +PlayResX: 1280 +PlayResY: 720 +YCbCr Matrix: TV.709 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: Dial-CH,Tensentype JiaLiDaYuanGB18030,38,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,2,10,10,30,1 +Style: Dial-CH2,Tensentype JiaLiDaYuanGB18030,36,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,8,10,10,36,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Comment: 0,0:00:00.00,0:00:00.00,Staff,,0,0,0,,Staff +Dialogue: 0,0:00:05.00,0:00:13.41,Staff,,0,0,0,,{=0}{\fscy100\t(5,8388,\fscy148.63)\fscx100\t(5,8388,\fscx148.63)\move(640,10,672.24,-73.86,5,8388)\alpha&HFF&\t(0,500,\alpha&H00&)\t(7910,8410,\alpha&HFF&)\blur5}本字幕由喵萌奶茶屋制作 仅供交流试看之用 请勿用于商业用途 \N翻译: Ronny 校对: 雨后飘雪 繁化: SashiharaRino 后期: MIR +Comment: 0,0:00:00.00,0:00:00.00,Staff,,0,0,0,,Title +Dialogu: 0,0:02:03.98,0:02:07.98,Title,,0,0,0,,{\clip(452,502,834,504)\pos(640,570)\c&H99A8F2&}BNW的誓言① +Dialogue: 0,0:02:03.98,0:02:07.98,Title,,0,0,0,,{\clip(452,504,834,506)\pos(640,570)\c&H99A8F2&}BNW的誓言① diff --git a/AssParser.Test/AssParserTest/format_14.ass b/AssParser.Test/AssParserTest/format_14.ass new file mode 100644 index 0000000..4bf0c44 --- /dev/null +++ b/AssParser.Test/AssParserTest/format_14.ass @@ -0,0 +1,24 @@ +[Script Info] +; Script generated by Aegisub 0-mod-d5c132a +; http://www.aegisub.org/ +Comment: [Processed by 繁化姬 dict-7ac3466c-r881 @ 2019/08/22 15:37:24 | https://zhconvert.org +Title: [Nekomoe kissaten] Uma Musume [14][BDRip].JPSC +ScriptType: v4.00+ +WrapStyle: 2 +ScaledBorderAndShadow: yes +PlayResX: 1280 +PlayResY: 720 +YCbCr Matrix: TV.709 + +[V4+ Styles] +Format: Names, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: Dial-CH,Tensentype JiaLiDaYuanGB18030,38,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,2,10,10,30,1 +Style: Dial-CH2,Tensentype JiaLiDaYuanGB18030,36,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,8,10,10,36,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Comment: 0,0:00:00.00,0:00:00.00,Staff,,0,0,0,,Staff +Dialogue: 0,0:00:05.00,0:00:13.41,Staff,,0,0,0,,{=0}{\fscy100\t(5,8388,\fscy148.63)\fscx100\t(5,8388,\fscx148.63)\move(640,10,672.24,-73.86,5,8388)\alpha&HFF&\t(0,500,\alpha&H00&)\t(7910,8410,\alpha&HFF&)\blur5}本字幕由喵萌奶茶屋制作 仅供交流试看之用 请勿用于商业用途 \N翻译: Ronny 校对: 雨后飘雪 繁化: SashiharaRino 后期: MIR +Comment: 0,0:00:00.00,0:00:00.00,Staff,,0,0,0,,Title +Dialogue: 0,0:02:03.98,0:02:07.98,Title,,0,0,0,,{\clip(452,502,834,504)\pos(640,570)\c&H99A8F2&}BNW的誓言① +Dialogue: 0,0:02:03.98,0:02:07.98,Title,,0,0,0,,{\clip(452,504,834,506)\pos(640,570)\c&H99A8F2&}BNW的誓言① diff --git a/AssParser.Test/AssParserTest/format_19.ass b/AssParser.Test/AssParserTest/format_19.ass new file mode 100644 index 0000000..8c67397 --- /dev/null +++ b/AssParser.Test/AssParserTest/format_19.ass @@ -0,0 +1,24 @@ +[Script Info] +; Script generated by Aegisub 0-mod-d5c132a +; http://www.aegisub.org/ +Comment: [Processed by 繁化姬 dict-7ac3466c-r881 @ 2019/08/22 15:37:24 | https://zhconvert.org +Title: [Nekomoe kissaten] Uma Musume [14][BDRip].JPSC +ScriptType: v4.00+ +WrapStyle: 2 +ScaledBorderAndShadow: yes +PlayResX: 1280 +PlayResY: 720 +YCbCr Matrix: TV.709 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: Dial-CH,Tensentype JiaLiDaYuanGB18030,38,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,2,10,10,30,1 +Style: Dial-CH2,Tensentype JiaLiDaYuanGB18030,36,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,8,10,10,36,1 + +[Events] +Format: Laye, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Comment: 0,0:00:00.00,0:00:00.00,Staff,,0,0,0,,Staff +Dialogue: 0,0:00:05.00,0:00:13.41,Staff,,0,0,0,,{=0}{\fscy100\t(5,8388,\fscy148.63)\fscx100\t(5,8388,\fscx148.63)\move(640,10,672.24,-73.86,5,8388)\alpha&HFF&\t(0,500,\alpha&H00&)\t(7910,8410,\alpha&HFF&)\blur5}本字幕由喵萌奶茶屋制作 仅供交流试看之用 请勿用于商业用途 \N翻译: Ronny 校对: 雨后飘雪 繁化: SashiharaRino 后期: MIR +Comment: 0,0:00:00.00,0:00:00.00,Staff,,0,0,0,,Title +Dialogue: 0,0:02:03.98,0:02:07.98,Title,,0,0,0,,{\clip(452,502,834,504)\pos(640,570)\c&H99A8F2&}BNW的誓言① +Dialogue: 0,0:02:03.98,0:02:07.98,Title,,0,0,0,,{\clip(452,504,834,506)\pos(640,570)\c&H99A8F2&}BNW的誓言① diff --git a/AssParser.Test/AssParserTest/style_15.ass b/AssParser.Test/AssParserTest/style_15.ass new file mode 100644 index 0000000..4255da6 --- /dev/null +++ b/AssParser.Test/AssParserTest/style_15.ass @@ -0,0 +1,24 @@ +[Script Info] +; Script generated by Aegisub 0-mod-d5c132a +; http://www.aegisub.org/ +Comment: [Processed by 繁化姬 dict-7ac3466c-r881 @ 2019/08/22 15:37:24 | https://zhconvert.org +Title: [Nekomoe kissaten] Uma Musume [14][BDRip].JPSC +ScriptType: v4.00+ +WrapStyle: 2 +ScaledBorderAndShadow: yes +PlayResX: 1280 +PlayResY: 720 +YCbCr Matrix: TV.709 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Styl: Dial-CH,Tensentype JiaLiDaYuanGB18030,38,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,2,10,10,30,1 +Style: Dial-CH2,Tensentype JiaLiDaYuanGB18030,36,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,8,10,10,36,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Comment: 0,0:00:00.00,0:00:00.00,Staff,,0,0,0,,Staff +Dialogue: 0,0:00:05.00,0:00:13.41,Staff,,0,0,0,,{=0}{\fscy100\t(5,8388,\fscy148.63)\fscx100\t(5,8388,\fscx148.63)\move(640,10,672.24,-73.86,5,8388)\alpha&HFF&\t(0,500,\alpha&H00&)\t(7910,8410,\alpha&HFF&)\blur5}本字幕由喵萌奶茶屋制作 仅供交流试看之用 请勿用于商业用途 \N翻译: Ronny 校对: 雨后飘雪 繁化: SashiharaRino 后期: MIR +Comment: 0,0:00:00.00,0:00:00.00,Staff,,0,0,0,,Title +Dialogue: 0,0:02:03.98,0:02:07.98,Title,,0,0,0,,{\clip(452,502,834,504)\pos(640,570)\c&H99A8F2&}BNW的誓言① +Dialogue: 0,0:02:03.98,0:02:07.98,Title,,0,0,0,,{\clip(452,504,834,506)\pos(640,570)\c&H99A8F2&}BNW的誓言①