• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zorbathut / dec / 11709205202

06 Nov 2024 05:57PM UTC coverage: 90.198% (-0.4%) from 90.637%
11709205202

push

github

zorbathut
Added the ability to reference class objects contained within Decs.

4748 of 5264 relevant lines covered (90.2%)

194623.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/src/Reader.cs
1
using System;
2
using System.Collections;
3
using System.Collections.Generic;
4

5
namespace Dec
6
{
7
    internal abstract class ReaderFileDec
8
    {
9
        public struct ReaderDec
10
        {
11
            public Type type;
12
            public string name;
13

14
            // this is a factory because we need to be able to generate lots of it with different paths
15
            // this is not a good solution
16
            // this needs to go away along with the whole polymorphic ReaderNode system
17
            public Func<Path, ReaderNodeParseable> nodeFactory;
18
            public Context context;
19

20
            public bool? abstrct;
21
            public string parent;
22
        }
23

24
        // this is a little awkward because it mutates state and should not be called twice. we should fix that
25
        public abstract List<ReaderDec> ParseDecs();
26
    }
27

28
    internal abstract class ReaderFileRecorder
29
    {
30
        public struct ReaderRef
31
        {
32
            public Type type;
33
            public string id;
34

35
            public ReaderNodeParseable node;
36
        }
37

38
        // this is a little awkward because it mutates state and should not be called twice. we should fix that
39
        public abstract List<ReaderRef> ParseRefs();
40
        public abstract ReaderNodeParseable ParseNode();
41
    }
42

43
    internal abstract class ReaderNode
44
    {
45
        public virtual bool AllowAsThis { get => true; }
535✔
46
        public abstract Recorder.IUserSettings UserSettings { get; }
47

48
        public abstract Context GetContext(); // note: this function must be really fast!
49

50
        public abstract ReaderNode GetChildNamed(string name);
51
        public abstract string[] GetAllChildren();
52

53
        public abstract int[] GetArrayDimensions(int rank);
54

55
        public abstract object ParseElement(Type type, object model, ReaderGlobals readerGlobals, Recorder.Settings recorderSettings);
56
    }
57

58
    internal abstract class ReaderNodeParseable : ReaderNode
59
    {
60
        public enum Metadata
61
        {
62
            Null,
63
            Ref,
64
            Class,
65
            Mode,
66
        }
67

68
        public override object ParseElement(Type type, object model, ReaderGlobals readerGlobals, Recorder.Settings recorderSettings)
69
        {
772,340✔
70
            return Serialization.ParseElement(new List<ReaderNodeParseable>() { this }, type, model, readerGlobals, recorderSettings);
772,340✔
71
        }
772,340✔
72

73
        public abstract string GetMetadata(Metadata metadata);
74
        public abstract string GetMetadataUnrecognized();
75
        public abstract string GetText();
76

77
        public abstract bool HasChildren();
78

79
        public abstract void ParseList(IList list, Type referencedType, ReaderGlobals readerGlobals, Recorder.Settings recorderSettings);
80
        public abstract void ParseArray(Array array, Type referencedType, ReaderGlobals readerGlobals, Recorder.Settings recorderSettings, int startOffset);
81
        public abstract void ParseDictionary(IDictionary dict, Type referencedKeyType, Type referencedValueType, ReaderGlobals readerGlobals, Recorder.Settings recorderSettings, bool permitPatch);
82
        public abstract void ParseHashset(object hashset, Type referencedType, ReaderGlobals readerGlobals, Recorder.Settings recorderSettings, bool permitPatch);
83
        public abstract void ParseStack(object hashset, Type referencedType, ReaderGlobals readerGlobals, Recorder.Settings recorderSettings);
84
        public abstract void ParseQueue(object hashset, Type referencedType, ReaderGlobals readerGlobals, Recorder.Settings recorderSettings);
85
        public abstract void ParseTuple(object[] parameters, Type referencedType, IList<string> parameterNames, ReaderGlobals readerGlobals, Recorder.Settings recorderSettings);
86
        public abstract void ParseReflection(object obj, ReaderGlobals readerGlobals, Recorder.Settings recorderSettings);
87
    }
88

89
    internal static class ReaderNodeExtension
90
    {
91
        public static string ToLowerString(this ReaderNodeParseable.Metadata metadata)
92
        {
20,678,207✔
93
            // Hardcode lowercase versions of all the enum names for performance.
94
            switch (metadata)
20,678,207✔
95
            {
96
                case ReaderNodeParseable.Metadata.Null: return "null";
4,778,667✔
97
                case ReaderNodeParseable.Metadata.Ref: return "ref";
4,779,202✔
98
                case ReaderNodeParseable.Metadata.Class: return "class";
4,778,667✔
99
                case ReaderNodeParseable.Metadata.Mode: return "mode";
6,341,671✔
100
                default: Dbg.Err($"Unknown attribute type {metadata}"); return "UNKNOWN";
×
101
            }
102
        }
20,678,207✔
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc