Skip to content
0.2.0-dev Download ZIP
70 lines ·2.9 KB Raw
1using EvilEngine.Adapters.Steam;
2
3namespace EvilEngine.Adapters.Tests;
4
5public sealed class KeyValuesTests
6{
7 [Fact]
8 public void ReadsASteamManifest()
9 {
10 var acf = KeyValues.Parse("""
11 "AppWorkshop"
12 {
13 "appid" "4000"
14 "WorkshopItemsInstalled"
15 {
16 "3821991353"
17 {
18 "size" "4452386"
19 "manifest" "1313277432769938788"
20 }
21 "131759821"
22 {
23 "manifest" "6356137708153723216"
24 }
25 }
26 }
27 """);
28
29 Assert.Equal("AppWorkshop", acf.Key);
30 Assert.Equal("4000", acf.Get("AppID"));
31 Assert.Equal(["3821991353", "131759821"], acf["WorkshopItemsInstalled"]!.Children.Select(item => item.Key));
32 Assert.Equal("1313277432769938788", acf["workshopitemsinstalled"]!["3821991353"]!.Get("manifest"));
33 }
34
35 [Fact]
36 public void ReadsGarrysModsConfigWithCommentsBareWordsAndConditionals()
37 {
38 var config = KeyValues.Parse("""
39 // DO NOT start lines with // in between { and }
40 "mountcfg"
41 {
42 // "cstrike" "C:\steamcmd\steamapps\common\Counter-Strike Source Dedicated Server\cstrike"
43 tf "C:\mytf2server\tf" [$WIN32]
44 "deltarune" "/home/me/Games/deltarune" // after a value
45 }
46 """);
47
48 Assert.Equal(["tf", "deltarune"], config.Children.Select(child => child.Key));
49 Assert.Equal(@"C:\mytf2server\tf", config.Get("tf"));
50 Assert.Equal("/home/me/Games/deltarune", config.Get("deltarune"));
51 }
52
53 [Fact]
54 public void ReadsAnEmptyBlock()
55 {
56 Assert.Empty(KeyValues.Parse("\"addonnomount\"\n{\n}\n").Children);
57 }
58
59 [Theory]
60 [InlineData("\"mountcfg\" { \"a\" \"b\"", "it ends inside a block")]
61 [InlineData("\"mountcfg\" { } }", "a '}' on line 1 closes nothing")]
62 [InlineData("\"mountcfg\" { \"a\" \"b }", "a quote on line 1 is never closed")]
63 [InlineData("{ }", "a '{' on line 1 has no key before it")]
64 [InlineData("\"lonely\"", "'lonely' on line 1 has no value")]
65 [InlineData("// nothing\n", "it holds no keys")]
66 public void RefusesBrokenText(string text, string reason)
67 {
68 Assert.Equal(reason, Assert.Throws<InvalidDataException>(() => KeyValues.Parse(text)).Message);
69 }
70}