Update to version 1.0.0 #3
4 changed files with 156 additions and 23 deletions
|
@ -39,8 +39,15 @@ class BofaParser
|
|||
var entry = ParseLine(l, line);
|
||||
if(!(entry.Type == .Bofa || entry.Type == .Text))
|
||||
delete l; //In these cases we have no useable data
|
||||
if(entry.Type == .Empty)
|
||||
{
|
||||
line++;
|
||||
continue;
|
||||
}
|
||||
if(entry.Type == .Error)
|
||||
pErrors.Add(line);
|
||||
if(entry.Type == .Text)
|
||||
defer delete l;
|
||||
|
||||
//If we are on the lowest level we can just add them here
|
||||
if(entry.Depth == 0 && entry.Type ==.Bofa)
|
||||
|
@ -48,18 +55,28 @@ class BofaParser
|
|||
if(pResult.FindIndex(scope (x) => { return x.Name == entry.Data.Bofa.Name;}) < 0)
|
||||
pResult.Add(entry.Data.Bofa);
|
||||
else
|
||||
{
|
||||
pErrors.Add(entry.Line); //Dublicate name error
|
||||
delete entry.Data.Bofa;
|
||||
}
|
||||
}
|
||||
else if(entry.Depth == 1 && entry.Type == .Text)
|
||||
{
|
||||
if(pResult[pResult.Count-1].Type == .Text)
|
||||
pResult[pResult.Count-1].Value.Text.Append(entry.Data.Text);
|
||||
pResult[pResult.Count-1].Value.Text.Append(scope $"\n{entry.Data.Text}");
|
||||
else
|
||||
pErrors.Add(entry.Line); //Bad text error
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.Depth--;
|
||||
if(pResult[pResult.Count-1].[Friend]_Insert(&entry) case .Err)
|
||||
{
|
||||
pErrors.Add(line);
|
||||
delete entry.Data.Bofa;
|
||||
}
|
||||
}
|
||||
|
||||
//if(pResult[pResult.Count-1].[Friend]_Insert(&entry) case .Err)
|
||||
//pErrors.Add(line);
|
||||
line++;
|
||||
}
|
||||
|
||||
|
@ -167,6 +184,7 @@ class BofaParser
|
|||
if (type.0 == "o" || type.0 == "a")
|
||||
{
|
||||
Bofa bofaRes = new Bofa();
|
||||
bofaRes.[Friend]_line = pLine;
|
||||
bofaRes.Name = nameres.0;
|
||||
bofaRes.Typename = typeName;
|
||||
if (type.0 == "o")
|
||||
|
|
|
@ -11,29 +11,32 @@ extension Bofa
|
|||
//See if we can insert and do so
|
||||
if(pToAdd.Depth == 0 || (pToAdd.Type == .Text && pToAdd.Depth == 1))
|
||||
{
|
||||
if(pToAdd.Type == .Text && _lastObject.Type == .Text)
|
||||
{
|
||||
_lastObject.Value.Text.Append(pToAdd.Data.Text);
|
||||
return .Ok;
|
||||
}
|
||||
else if(_lastObject.Type == .Object)
|
||||
{
|
||||
_lastObject.Value.Object.Add(pToAdd.Data.Bofa.Name, pToAdd.Data.Bofa);
|
||||
_lastObject._lastObject = pToAdd.Data.Bofa;
|
||||
return .Ok;
|
||||
if(pToAdd.Type == .Text && Type == .Text)
|
||||
{
|
||||
Value.Text.Append(scope $"\n{pToAdd.Data.Text}");
|
||||
return .Ok;
|
||||
}
|
||||
else if(Type == .Object)
|
||||
{
|
||||
if(Value.Object.ContainsKey(pToAdd.Data.Bofa.Name))
|
||||
return .Err;
|
||||
Value.Object.Add(pToAdd.Data.Bofa.Name, pToAdd.Data.Bofa);
|
||||
_lastObject = pToAdd.Data.Bofa;
|
||||
return .Ok;
|
||||
|
||||
}
|
||||
else if(_lastObject.Type == .Array)
|
||||
{
|
||||
_lastObject.Value.Array.Add(pToAdd.Data.Bofa);
|
||||
_lastObject._lastObject = pToAdd.Data.Bofa;
|
||||
return .Ok;
|
||||
}
|
||||
}
|
||||
else if(Type == .Array)
|
||||
{
|
||||
Value.Array.Add(pToAdd.Data.Bofa);
|
||||
_lastObject = pToAdd.Data.Bofa;
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
return .Err; //Cannot insert here
|
||||
}
|
||||
|
||||
//Can we even go deeper
|
||||
if(!(_lastObject.Type == .Object || _lastObject.Type == .Array))
|
||||
if(_lastObject == null || !(_lastObject.Type == .Object || _lastObject.Type == .Array))
|
||||
return .Err;
|
||||
|
||||
pToAdd.Depth--;
|
||||
|
|
|
@ -6,24 +6,131 @@ using System.Collections;
|
|||
|
||||
class Default
|
||||
{
|
||||
[Test]
|
||||
public static void Default_Test_1()
|
||||
[Test(Name="Parsing all Types")]
|
||||
public static void Parsing_1()
|
||||
{
|
||||
|
||||
String content = """
|
||||
l one line of text
|
||||
b bool true
|
||||
# saoidsaodsad
|
||||
t text goes here
|
||||
- Text addendum
|
||||
n tone 12.5
|
||||
#husdhfiudshfds
|
||||
bn biggie 65645645645.6
|
||||
i int 234345
|
||||
|
||||
|
||||
bi bint 38432847329847329
|
||||
o object
|
||||
b content true
|
||||
a array
|
||||
b content true
|
||||
b content true
|
||||
""";
|
||||
List<Bofa> output = new .();
|
||||
List<int64> errors = new .();
|
||||
BofaParser.Parse(content, output, errors);
|
||||
|
||||
Test.Assert(output.Count == 9);
|
||||
Test.Assert(output[7].Value.Object.Count == 1);
|
||||
Test.Assert(output[8].Value.Array.Count == 2);
|
||||
Test.Assert(errors.Count == 0);
|
||||
|
||||
DeleteContainerAndItems!(output);
|
||||
delete errors;
|
||||
}
|
||||
|
||||
[Test(Name="Parsing Number")]
|
||||
public static void Parsing_2()
|
||||
{
|
||||
|
||||
String content = """
|
||||
n number 1.0
|
||||
n number_1 345
|
||||
bn bignumber 2132432432.56564
|
||||
i integer 21324
|
||||
bi biginteger 565765765765765
|
||||
""";
|
||||
List<Bofa> output = new .();
|
||||
List<int64> errors = new .();
|
||||
BofaParser.Parse(content, output, errors);
|
||||
|
||||
Test.Assert(output.Count == 5);
|
||||
Test.Assert(errors.Count == 0);
|
||||
|
||||
DeleteContainerAndItems!(output);
|
||||
delete errors;
|
||||
}
|
||||
|
||||
[Test(Name="Parsing Multiline Text")]
|
||||
public static void Parsing_3()
|
||||
{
|
||||
|
||||
String content = """
|
||||
t Multiline text
|
||||
- several lines
|
||||
- can be added to a single thing
|
||||
- this does mean
|
||||
- that stuff has to be appended
|
||||
- but thats fine
|
||||
""";
|
||||
List<Bofa> output = new .();
|
||||
List<int64> errors = new .();
|
||||
BofaParser.Parse(content, output, errors);
|
||||
|
||||
Test.Assert(output.Count == 1);
|
||||
Test.Assert(errors.Count == 0);
|
||||
|
||||
DeleteContainerAndItems!(output);
|
||||
delete errors;
|
||||
}
|
||||
|
||||
[Test(Name="Parsing Objects")]
|
||||
public static void Parsing_4()
|
||||
{
|
||||
|
||||
String content = """
|
||||
o object
|
||||
n member 1
|
||||
b other true
|
||||
|
||||
|
||||
o obj
|
||||
o deeper
|
||||
o even deeper
|
||||
n member 1
|
||||
""";
|
||||
List<Bofa> output = new .();
|
||||
List<int64> errors = new .();
|
||||
BofaParser.Parse(content, output, errors);
|
||||
|
||||
Test.Assert(output.Count == 2);
|
||||
Test.Assert(errors.Count == 0);
|
||||
|
||||
DeleteContainerAndItems!(output);
|
||||
delete errors;
|
||||
}
|
||||
|
||||
[Test(Name="Parsing Dublicate Key")]
|
||||
public static void Parsing_5()
|
||||
{
|
||||
|
||||
String content = """
|
||||
n number 1
|
||||
n number 2
|
||||
|
||||
o obj
|
||||
n member 1
|
||||
n member 2
|
||||
""";
|
||||
List<Bofa> output = new .();
|
||||
List<int64> errors = new .();
|
||||
BofaParser.Parse(content, output, errors);
|
||||
|
||||
Test.Assert(output.Count == 2);
|
||||
Test.Assert(errors.Count == 2);
|
||||
|
||||
DeleteContainerAndItems!(output);
|
||||
delete errors;
|
||||
|
|
5
src/Testing/Profiling.bf
Normal file
5
src/Testing/Profiling.bf
Normal file
|
@ -0,0 +1,5 @@
|
|||
namespace Bofa.Testing;
|
||||
|
||||
class Profiling
|
||||
{
|
||||
}
|
Loading…
Add table
Reference in a new issue