Skip to content

Commit

Permalink
tests: fix type parser
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-buchanan committed Jun 9, 2024
1 parent adfb723 commit 4fcaeac
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/db/decaf.sqlite/SqliteTypeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public string Parse(Type type)
{
if (type == typeof(string))
return "text";
if (type == typeof(int))
if (type == typeof(int) ||
type == typeof(long))
return "integer";
if (type == typeof(decimal) ||
type == typeof(float) ||
Expand Down
48 changes: 48 additions & 0 deletions tests/decaf.sqlite.tests/SqliteTypeParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using Xunit;

namespace decaf.sqlite.tests;

public class SqliteTypeParserTests
{
[Theory]
[MemberData(nameof(TestCases))]
public void CheckValueParses(Type input, string expected)
{
// Arrange
var typeParser = new SqliteTypeParser();

// Act
var result = typeParser.Parse(input);

// Assert
result.Should().Be(expected);
}

public static IEnumerable<object[]> TestCases
{
get
{
yield return [typeof(string), "text"];
yield return [typeof(String), "text"];
yield return [typeof(int), "integer"];
yield return [typeof(Int32), "integer"];
yield return [typeof(decimal), "float"];
yield return [typeof(float), "float"];
yield return [typeof(double), "float"];
yield return [typeof(Single), "float"];
yield return [typeof(bool), "boolean"];
yield return [typeof(Boolean), "boolean"];
yield return [typeof(byte), "blob"];
yield return [typeof(DateTime), "timestamp"];
yield return [typeof(DateTimeOffset), "timestamp"];
yield return [null, "text"];
yield return [typeof(char), "text"];
yield return [typeof(long), "integer"];
yield return [typeof(Int64), "integer"];
yield return [typeof(object), "text"];
}
}
}

0 comments on commit 4fcaeac

Please sign in to comment.