Skip to content

Commit

Permalink
Fixes handling of symbols with unknown text in GetTypeAnnotations. (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
byronlin13 authored Mar 27, 2020
1 parent e4764f8 commit d01176a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
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

0 comments on commit d01176a

Please sign in to comment.