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

.NET port #281

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8df9ab7
Ignore C# working directories.
nedtwigg Mar 22, 2024
4cae936
Add a project structure.
nedtwigg Mar 22, 2024
bec0a79
Add the projects to the solution.
nedtwigg Mar 22, 2024
f1471fc
Set LangVersion to 8.0
nedtwigg Mar 23, 2024
478365f
Fix compile warnings.
nedtwigg Mar 23, 2024
74f7671
Add CI for the c# build.
nedtwigg Mar 23, 2024
1d9ced2
Formatted.
nedtwigg Mar 23, 2024
71df5f0
Fix the CI and add formatting.
nedtwigg Mar 23, 2024
8dd1ae5
Break formatting.
nedtwigg Mar 23, 2024
01d7d30
First cut at a Slice class and its test.
nedtwigg Mar 23, 2024
ba89965
Run the tests on the server.
nedtwigg Mar 23, 2024
fee5b5f
Less whitespace.
nedtwigg Mar 23, 2024
b32b4a9
Bump LangVer to 10 so that we can have file-scoped namespace declarat…
nedtwigg Mar 23, 2024
3216a2c
For testing, bump to LangVersion 11 for multiline string literals.
nedtwigg Mar 23, 2024
04bcecb
Break a test to see what it looks like in CI.
nedtwigg Mar 23, 2024
f97ab70
Also fix formatting.
nedtwigg Mar 23, 2024
e779b76
Revert "Break a test to see what it looks like in CI."
nedtwigg Mar 23, 2024
e958c99
Selfie and Guts as one-shotted by Claude.
nedtwigg Mar 23, 2024
e9993ab
Remove `Slice.cs`.
nedtwigg Mar 23, 2024
8eb33ec
Progress on `ArrayMap`.
nedtwigg Mar 24, 2024
ff7afc1
ArrayMap is passing tests!
nedtwigg Mar 24, 2024
a8106ed
Revert "Remove `Slice.cs`."
nedtwigg Mar 24, 2024
0b9096f
Fix the namespaces of `Slice` and `Guts`.
nedtwigg Mar 24, 2024
d9f6d92
Rename our giant files because they're too much to handle for now.
nedtwigg Mar 24, 2024
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
29 changes: 29 additions & 0 deletions .github/workflows/csharp-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
push:
branches: [main]
pull_request:
paths:
- 'dotnet/**'
defaults:
run:
working-directory: dotnet
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
strategy:
fail-fast: false
matrix:
jre: [11]
os: [ubuntu-latest, windows-latest]
dotnet-version: ['6.0.x']
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
- run: dotnet format --verify-no-changes ./Selfie.sln
- run: dotnet build
- run: dotnet test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
build/
bin/
.DS_Store
__pycache__/
__pycache__/
obj/
15 changes: 15 additions & 0 deletions dotnet/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.cs]
csharp_style_namespace_declarations = file_scoped:error
csharp_style_var_for_built_in_types = false:suggestion
csharp_style_var_when_type_is_apparent = false:suggestion
csharp_style_var_elsewhere = false:suggestion
csharp_new_line_before_open_brace = none
104 changes: 104 additions & 0 deletions dotnet/Selfie.Lib.Tests/ArrayMapTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DiffPlug.Selfie.Lib.Tests;

[TestFixture]
public class ArrayMapTest {
[Test]
public void Empty() {
var empty = ArrayMap<string, string>.Empty;
AssertEmpty(empty);
}

[Test]
public void Single() {
var empty = ArrayMap<string, string>.Empty;
var single = empty.Plus("one", "1");
AssertEmpty(empty);
AssertSingle(single, "one", "1");
}

[Test]
public void Double() {
var empty = ArrayMap<string, string>.Empty;
var single = empty.Plus("one", "1");
var doubleMap = single.Plus("two", "2");
AssertEmpty(empty);
AssertSingle(single, "one", "1");
AssertDouble(doubleMap, "one", "1", "two", "2");
// ensure sorted also
AssertDouble(single.Plus("a", "sorted"), "a", "sorted", "one", "1");

var ex = Assert.Throws<ArgumentException>(() => single.Plus("one", "2"));
Assert.That(ex.Message, Is.EqualTo("Key already exists: one"));
}

// [Test]
// public void Of() {
// AssertEmpty(ArrayMap<string, string>.Of());
// AssertSingle(ArrayMap<string, string>.Of(new KeyValuePair<string, string>("one", "1") });
// AssertDouble(ArrayMap<string, string>.Of(new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("one", "1"), new KeyValuePair<string, string>("two", "2") }), "one", "1", "two", "2");
// AssertDouble(ArrayMap<string, string>.Of(new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("two", "2"), new KeyValuePair<string, string>("one", "1") }), "one", "1", "two", "2");
// }

// [Test]
// public void Multi() {
// AssertTriple(
// ArrayMap.Empty<string, string>().Plus("1", "one").Plus("2", "two").Plus("3", "three"),
// "1", "one", "2", "two", "3", "three");
// AssertTriple(
// ArrayMap.Empty<string, string>().Plus("2", "two").Plus("3", "three").Plus("1", "one"),
// "1", "one", "2", "two", "3", "three");
// AssertTriple(
// ArrayMap.Empty<string, string>().Plus("3", "three").Plus("1", "one").Plus("2", "two"),
// "1", "one", "2", "two", "3", "three");
// }

private void AssertEmpty(IDictionary<string, string> map) {
Assert.That(map.Count, Is.EqualTo(0));
Assert.IsFalse(map.Keys.Any());
Assert.IsFalse(map.Values.Any());
Assert.IsFalse(map.ContainsKey("key"));
Assert.That(map.FirstOrDefault().Value, Is.EqualTo(default(string)));
}

private void AssertSingle(IDictionary<string, string> map, string key, string value) {
Assert.That(map.Count, Is.EqualTo(1));
Assert.IsTrue(map.ContainsKey(key));
Assert.That(map[key], Is.EqualTo(value));
var singleEntry = new KeyValuePair<string, string>(key, value);
Assert.IsTrue(map.Contains(singleEntry));
}

private void AssertDouble(IDictionary<string, string> map, string key1, string value1, string key2, string value2) {
Assert.That(map.Count, Is.EqualTo(2));
Assert.IsTrue(map.ContainsKey(key1));
Assert.IsTrue(map.ContainsKey(key2));
Assert.That(map[key1], Is.EqualTo(value1));
Assert.That(map[key2], Is.EqualTo(value2));
var entry1 = new KeyValuePair<string, string>(key1, value1);
var entry2 = new KeyValuePair<string, string>(key2, value2);
Assert.IsTrue(map.Contains(entry1));
Assert.IsTrue(map.Contains(entry2));
}

private void AssertTriple(IDictionary<string, string> map, string key1, string value1, string key2, string value2, string key3, string value3) {
Assert.That(map.Count, Is.EqualTo(3));
Assert.IsTrue(map.ContainsKey(key1));
Assert.IsTrue(map.ContainsKey(key2));
Assert.IsTrue(map.ContainsKey(key3));
Assert.That(map[key1], Is.EqualTo(value1));
Assert.That(map[key2], Is.EqualTo(value2));
Assert.That(map[key3], Is.EqualTo(value3));
var entry1 = new KeyValuePair<string, string>(key1, value1);
var entry2 = new KeyValuePair<string, string>(key2, value2);
var entry3 = new KeyValuePair<string, string>(key3, value3);
Assert.IsTrue(map.Contains(entry1));
Assert.IsTrue(map.Contains(entry2));
Assert.IsTrue(map.Contains(entry3));
}
}

24 changes: 24 additions & 0 deletions dotnet/Selfie.Lib.Tests/Selfie.Lib.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>11.0</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>DiffPlug.Selfie.Lib</RootNamespace>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Selfie.Lib\Selfie.Lib.csproj" />
</ItemGroup>
</Project>
20 changes: 20 additions & 0 deletions dotnet/Selfie.Lib.Tests/guts/SliceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NUnit.Framework;

namespace DiffPlug.Selfie.Lib.Guts.Tests;

[TestFixture]
public class SliceTest {
[Test]
public void UnixLine() {
var singleLine = new Slice("A single line");
Assert.That(singleLine.UnixLine(1).ToString(), Is.EqualTo("A single line"));

var oneTwoThree = new Slice("\nI am the first\nI, the second\n\nFOURTH\n");
Assert.That(oneTwoThree.UnixLine(1).ToString(), Is.EqualTo(""));
Assert.That(oneTwoThree.UnixLine(2).ToString(), Is.EqualTo("I am the first"));
Assert.That(oneTwoThree.UnixLine(3).ToString(), Is.EqualTo("I, the second"));
Assert.That(oneTwoThree.UnixLine(4).ToString(), Is.EqualTo(""));
Assert.That(oneTwoThree.UnixLine(5).ToString(), Is.EqualTo("FOURTH"));
Assert.That(oneTwoThree.UnixLine(6).ToString(), Is.EqualTo(""));
}
}
Loading