Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update zero symbol to return default import location #97

Merged
merged 6 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Amazon.IonDotnet.Tests/Common/ReaderTestCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ public static void ReadTypeAnnotationSymbols_ZeroSymbol(IIonReader reader)
Assert.AreEqual(IonType.Int, reader.CurrentType);
Assert.AreEqual(18, reader.IntValue());
Assert.AreEqual(1, reader.GetTypeAnnotationSymbols().Count());
Assert.IsTrue(reader.GetTypeAnnotationSymbols().Any(a => a.Text == null));

// Commented out following assertion due to bug: https://github.com/amzn/ion-dotnet/issues/89
//Assert.IsTrue(reader.GetTypeAnnotationSymbols().Any(a => a.Text == null && a.ImportLocation == null));
Assert.IsTrue(reader.GetTypeAnnotationSymbols().Any(a => a.Text == null && a.ImportLocation == default));
}

public static void ReadTypeAnnotationSymbols_AssertNoUnknownSymbolException(IIonReader reader)
Expand Down
4 changes: 4 additions & 0 deletions Amazon.IonDotnet/Internals/Text/RawTextReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ private SymbolToken ParseSymbolToken(StringBuilder sb, int token)
break;
}

if (text == null && sid == 0)
{
return new SymbolToken(text, sid);
}
return new SymbolToken(text, sid, new ImportLocation(GetSymbolTable().Name, sid));
}

Expand Down
22 changes: 14 additions & 8 deletions Amazon.IonDotnet/Internals/Text/SystemTextReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,24 +526,30 @@ public override string[] GetTypeAnnotations()
for (int index = 0; index < _annotations.Count; index++)
{
SymbolToken symbolToken = _annotations[index];
if (symbolToken.Text is null && symbolToken.ImportLocation != default)
if (symbolToken.Text is null)
{
ISymbolTable symtab = GetSymbolTable();

string text = symtab.FindKnownSymbol(symbolToken.ImportLocation.Sid);
if (text == null)
if (symbolToken.ImportLocation == default)
{
throw new UnknownSymbolException(symbolToken.ImportLocation.Sid);
throw new UnknownSymbolException(symbolToken.Sid);
}
else
{
ISymbolTable symtab = GetSymbolTable();

string text = symtab.FindKnownSymbol(symbolToken.ImportLocation.Sid);
if (text == null)
{
throw new UnknownSymbolException(symbolToken.ImportLocation.Sid);
}

annotations[index] = symtab.FindKnownSymbol(symbolToken.ImportLocation.Sid);
annotations[index] = symtab.FindKnownSymbol(symbolToken.ImportLocation.Sid);
}
}
else
{
annotations[index] = symbolToken.Text;
}
}

return annotations;
}

Expand Down