Skip to content

Commit

Permalink
Allow use Main-less Program.cs (#155)
Browse files Browse the repository at this point in the history
Fixes #154
  • Loading branch information
kant2002 authored May 28, 2023
1 parent ac33426 commit 4104805
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ public static TypeEnclosure GetTypeEnclosure(this INamedTypeSymbol symbol)
var suffixBuilder = new StringBuilder();

// Namespace open
if (symbol.ContainingNamespace is not null)
var hasNamespace = symbol.ContainingNamespace is not null && symbol.ContainingNamespace.ToDisplayString() != "<global namespace>";
if (hasNamespace)
{
prefixBuilder
.Append("namespace ")
.AppendLine(symbol.ContainingNamespace.ToDisplayString())
.AppendLine(symbol.ContainingNamespace!.ToDisplayString())
.AppendLine("{");
}

Expand All @@ -111,7 +112,7 @@ public static TypeEnclosure GetTypeEnclosure(this INamedTypeSymbol symbol)
}

// Namespace close
if (symbol.ContainingNamespace is not null) suffixBuilder.AppendLine("}");
if (hasNamespace) suffixBuilder.AppendLine("}");

return new(prefixBuilder.ToString(), suffixBuilder.ToString());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2021-2022 Yoakke.
// Licensed under the Apache License, Version 2.0.
// Source repository: https://github.com/LanguageDev/Yoakke

using Xunit;
using Yoakke.SynKit.Lexer.Attributes;
using Yoakke.SynKit.Lexer.Tests;
using Yoakke.SynKit.Lexer;
using IgnoreAttribute = Yoakke.SynKit.Lexer.Attributes.IgnoreAttribute;


public enum NoNamespaceTokenType
{
[Ignore][Regex(Regexes.Whitespace)] Whitespace,

[Error] Error,
[End] End,

[Token("IF")][Token("if")] KwIf,
[Token("else")] KwElse,
[Regex(Regexes.Identifier)] Identifier,
[Token("+")] Plus,
[Token("-")] Minus,
[Regex(Regexes.IntLiteral)] Number,
}

[Lexer(typeof(NoNamespaceTokenType))]
internal partial class NoNamespaceLexer
{
}

public partial class NoNamespaceLexerGeneratorTests : TestBase<NoNamespaceTokenType>
{

[Fact]
public void Empty()
{
var lexer = new NoNamespaceLexer(string.Empty);
Assert.Equal(Token(string.Empty, NoNamespaceTokenType.End, Range((0, 0), 0)), lexer.Next());
}

[Fact]
public void EmptySpaces()
{
var lexer = new NoNamespaceLexer(" ");
Assert.Equal(Token(string.Empty, NoNamespaceTokenType.End, Range((0, 3), 0)), lexer.Next());
}

[Fact]
public void SimpleSequence()
{
var lexer = new NoNamespaceLexer("if asd+b 123");
Assert.Equal(Token("if", NoNamespaceTokenType.KwIf, Range((0, 0), 2)), lexer.Next());
Assert.Equal(Token("asd", NoNamespaceTokenType.Identifier, Range((0, 6), 3)), lexer.Next());
Assert.Equal(Token("+", NoNamespaceTokenType.Plus, Range((0, 9), 1)), lexer.Next());
Assert.Equal(Token("b", NoNamespaceTokenType.Identifier, Range((0, 10), 1)), lexer.Next());
Assert.Equal(Token("123", NoNamespaceTokenType.Number, Range((0, 12), 3)), lexer.Next());
Assert.Equal(Token(string.Empty, NoNamespaceTokenType.End, Range((0, 15), 0)), lexer.Next());
}
}

0 comments on commit 4104805

Please sign in to comment.