Coverage report for Casbin.Parser.AST.Types.

Generated at 18/02/2019 12:10:19 by DelphiCodeCoverage - an open source tool for Delphi Code Coverage.

Statistics for Casbin.Parser.AST.Types.pas

Number of lines covered43
Number of lines with code gen46
Line coverage93%


1
// Copyright 2018 by John Kouraklis and Contributors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
unit Casbin.Parser.AST.Types;
15
16
interface
17
18
uses
19
  Casbin.Model.Sections.Types, System.Generics.Collections, Casbin.Effect.Types;
20
21
type
22
  TBaseNode = class;
23
  TNodeCollection = class;
24
  THeaderNode = class;
25
  TChildNode = class;
26
  TAssertionNode = class;
27
28
  TBaseNode = class
29
  private
30
    fKey: string;
31
    fValue: string;
32
  public
33
    function toOutputString: string; virtual;
34
35
    property Key: string read fKey write fKey;
36
    property Value: string read fValue write fValue;
37
  end;
38
39
  TNodeCollection = class
40
  private
41
    fHeaders: TObjectList<THeaderNode>;
42
  public
43
    constructor Create;
44
    destructor Destroy; override;
45
    function toOutputString: string;
46
47
    property Headers: TObjectList<THeaderNode> read fHeaders write fHeaders;
48
  end;
49
50
  THeaderNode = class (TBaseNode)
51
  private
52
    fSectionType: TSectionType;
53
    fStatementNode: TObjectList<TChildNode>;
54
  public
55
    constructor Create;
56
    destructor Destroy; override;
57
    function toOutputString: string; override;
58
59
    property SectionType: TSectionType read fSectionType write fSectionType;
60
    property ChildNodes: TObjectList<TChildNode> read fStatementNode
61
                                                        write fStatementNode;
62
  end;
63
64
  TChildNode = class (TBaseNode)
65
  private
66
    fAssertionList: TObjectList<TAssertionNode>;
67
  public
68
    constructor Create;
69
    destructor Destroy; override;
70
    function toOutputString: string; override;
71
72
    property AssertionList: TObjectList<TAssertionNode> read fAssertionList write
73
        fAssertionList;
74
  end;
75
76
  TAssertionNode = class (TChildNode)
77
  public
78
    function toOutputString: string; override;
79
  end;
80
81
  TEffectNode = class (TChildNode)
82
  private
83
    fEffectCondition: TEffectCondition;
84
  public
85
    property EffectCondition: TEffectCondition read fEffectCondition write
86
        fEffectCondition;
87
  end;
88
89
implementation
90
91
uses
92
  System.SysUtils, System.StrUtils;
93
94
constructor TNodeCollection.Create;
95
begin
96
  inherited;
97
  fHeaders:=TObjectList<THeaderNode>.Create;
98
end;
99
100
destructor TNodeCollection.Destroy;
101
begin
102
  fHeaders.Free;
103
  inherited;
104
end;
105
106
function TNodeCollection.toOutputString: string;
107
var
108
  header: THeaderNode;
109
begin
110
  result:='';
111
  for header in fHeaders do
112
    Result:=Result+header.toOutputString+sLineBreak;
113
end;
114
115
constructor THeaderNode.Create;
116
begin
117
  inherited;
118
  fStatementNode:=TObjectList<TChildNode>.Create;
119
end;
120
121
destructor THeaderNode.Destroy;
122
begin
123
  fStatementNode.Free;
124
  inherited;
125
end;
126
127
function THeaderNode.toOutputString: string;
128
var
129
  i: Integer;
130
begin
131
  Result:='['+Value+']'+sLineBreak;
132
  for i:=0 to fStatementNode.Count-1 do
133
  begin
134
      Result:=Result+fStatementNode.Items[i].toOutputString+sLineBreak;
135
  end;
136
  if fSectionType=stPolicyRules then
137
    Result:=ReplaceStr(Result, '=', ',');
138
end;
139
140
{ TBaseNode }
141
142
function TBaseNode.toOutputString: string;
143
begin
144
  Result:=fValue;
145
end;
146
147
constructor TChildNode.Create;
148
begin
149
  inherited;
150
  fAssertionList:=TObjectList<TAssertionNode>.Create;
151
end;
152
153
destructor TChildNode.Destroy;
154
begin
155
  fAssertionList.Free;
156
  inherited;
157
end;
158
159
{ TChildNode }
160
161
function TChildNode.toOutputString: string;
162
begin
163
  Result:=Trim(fKey)+'='+Trim(fValue);
164
end;
165
166
{ TAssertionNode }
167
168
function TAssertionNode.toOutputString: string;
169
begin
170
  Result:=Trim(fKey)+'.'+Trim(fValue);
171
end;
172
173
end.