Skip to content

Commit ec0c54e

Browse files
committed
first commit
0 parents  commit ec0c54e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+10573
-0
lines changed

.editorconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# http://editorconfig.org
2+
3+
# This file is the top-most EditorConfig file
4+
root = true
5+
6+
# All Files
7+
[*]
8+
charset = utf-8
9+
end_of_line = crlf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
indent_style = space
13+
indent_size = 4
14+
15+
# Configuration Files
16+
[*.{json,xml,props,targets,nuspec,resx,ruleset,config,yml}]
17+
indent_size = 2
18+
19+
# Markdown Files
20+
[*.md]
21+
trim_trailing_whitespace = false
22+
23+
# Web Files
24+
[*.{htm,html,cshtml,js,ts,css,scss}]
25+
indent_size = 2

.gitattributes

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

.github/copilot-instructions.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Copilot Instructions for NCode.Buffers
2+
3+
## Test Project Conventions
4+
5+
### Unit Test Style
6+
7+
When writing or modifying unit tests in this project:
8+
9+
- **Do NOT use** `// Arrange`, `// Act`, `// Assert` comments in test methods
10+
- Use blank lines to separate the logical sections of a test instead of comments
11+
- Keep tests concise and readable without AAA comment annotations
12+
13+
### Example
14+
15+
```csharp
16+
[Fact]
17+
public void MyMethod_WhenCondition_ExpectedBehavior()
18+
{
19+
var input = "test";
20+
21+
var result = MyMethod(input);
22+
23+
Assert.Equal("expected", result);
24+
}
25+
```
26+
27+
## Code Style Conventions
28+
29+
### Collection Expressions
30+
31+
Use C# 12+ collection expressions instead of traditional array/collection initialization:
32+
33+
```csharp
34+
// Preferred
35+
byte[] data = [1, 2, 3, 4, 5];
36+
List<string> names = ["Alice", "Bob"];
37+
int[] empty = [];
38+
39+
// Avoid
40+
var data = new byte[] { 1, 2, 3, 4, 5 };
41+
var names = new List<string> { "Alice", "Bob" };
42+
var empty = Array.Empty<int>();
43+
```
44+
45+
### Constants for Literals
46+
47+
Use `const` for any literal values of any type instead of `var`:
48+
49+
```csharp
50+
// Preferred
51+
const string expected = "hello";
52+
const int count = 5;
53+
const char separator = ',';
54+
const double rate = 0.15;
55+
56+
// Avoid
57+
var expected = "hello";
58+
var count = 5;
59+
var separator = ',';
60+
var rate = 0.15;
61+
```
62+
63+
### UTF-8 String Literals
64+
65+
Use C# 11+ UTF-8 string literals (`u8` suffix) when working with byte arrays that represent valid UTF-8 text:
66+
67+
```csharp
68+
// Preferred
69+
var bytes = "Hello"u8.ToArray();
70+
var utf8Bytes = "café"u8.ToArray();
71+
var emojiBytes = "😀"u8.ToArray();
72+
73+
// Avoid
74+
byte[] bytes = [72, 101, 108, 108, 111];
75+
byte[] utf8Bytes = [0xC3, 0xA9]; // 'é' in UTF-8
76+
byte[] emojiBytes = [0xF0, 0x9F, 0x98, 0x80]; // 😀 in UTF-8
77+
```
78+
79+
Note: Use explicit byte arrays for invalid UTF-8 sequences or when testing error conditions.
80+
81+
## Code Quality
82+
83+
### ReSharper/IDE Warnings
84+
85+
Always fix ReSharper and IDE warnings/suggestions when modifying code. Common fixes include:
86+
87+
- Use collection expressions where applicable (but cast when needed for generic type inference, e.g., `(byte[])[1, 2, 3]` for `ReadOnlyMemory<T>` parameters)
88+
- Remove redundant type specifications
89+
- Use `const` for compile-time constant values
90+
- Ensure all record struct properties are accessed to avoid "never accessed" warnings
91+
92+
### xUnit Assertion Best Practices
93+
94+
Use the appropriate xUnit assertions for collection sizes instead of `Assert.Equal`:
95+
96+
```csharp
97+
// Preferred
98+
Assert.Empty(collection); // For count == 0
99+
Assert.Single(collection); // For count == 1
100+
101+
// Avoid
102+
Assert.Equal(0, collection.Count);
103+
Assert.Equal(1, collection.Count);
104+
```
105+
106+
For counts greater than 1, `Assert.Equal(expectedCount, collection.Count)` is acceptable.
107+
108+
### Test Organization with Regions
109+
110+
Organize unit tests within a test class using `#region` directives to group tests by the method or property under test:
111+
112+
```csharp
113+
public class MyClassTests
114+
{
115+
#region Constructor Tests
116+
117+
[Fact]
118+
public void Constructor_WithValidInput_CreatesInstance()
119+
{
120+
// test code
121+
}
122+
123+
[Fact]
124+
public void Constructor_WithNullInput_ThrowsException()
125+
{
126+
// test code
127+
}
128+
129+
#endregion
130+
131+
#region MyMethod Tests
132+
133+
[Fact]
134+
public void MyMethod_WhenCondition_ExpectedBehavior()
135+
{
136+
// test code
137+
}
138+
139+
#endregion
140+
141+
#region MyProperty Tests
142+
143+
[Fact]
144+
public void MyProperty_ReturnsExpectedValue()
145+
{
146+
// test code
147+
}
148+
149+
#endregion
150+
}
151+
```
152+
153+
Region naming conventions:
154+
- Use `Constructor Tests` for constructor tests
155+
- Use `{MethodName} Tests` for method tests (e.g., `Dispose Tests`)
156+
- Use `{PropertyName} Property Tests` for property tests (e.g., `Span Property Tests`)
157+
- Use `Generic Type Tests` for tests verifying generic type parameter behavior

.github/workflows/main.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+
name: CI
4+
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
release:
12+
types: ["published"]
13+
14+
env:
15+
BUILD_CONFIGURATION: Release
16+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
17+
DOTNET_NOLOGO: true
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Setup .NET
25+
uses: actions/setup-dotnet@v4
26+
with:
27+
dotnet-version: 10.0.x
28+
- name: Extract version from tag
29+
uses: dhkatz/get-version-action@v3.0.0
30+
id: extract_version
31+
- name: Restore dependencies
32+
run: dotnet restore
33+
- name: Build
34+
run: dotnet build --no-restore --configuration ${BUILD_CONFIGURATION} /p:Version="${BUILD_VERSION}"
35+
env:
36+
BUILD_VERSION: ${{ steps.extract_version.outputs.is-semver == 'true' && steps.extract_version.outputs.version-without-v || '0.0.0' }}
37+
- name: Upload artifacts
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: binaries
41+
path: |
42+
./*/bin/*
43+
./*/obj/*
44+
if-no-files-found: error
45+
retention-days: 5
46+
47+
test:
48+
needs: [build]
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
- name: Download artifacts
53+
uses: actions/download-artifact@v4
54+
with:
55+
name: binaries
56+
- name: Setup .NET
57+
uses: actions/setup-dotnet@v4
58+
with:
59+
dotnet-version: 10.0.x
60+
- name: Restore dependencies
61+
run: dotnet restore
62+
- name: Run rests
63+
run: dotnet test --no-build --verbosity normal --configuration ${BUILD_CONFIGURATION} --logger trx
64+
- name: Publish tests
65+
uses: dorny/test-reporter@v1
66+
if: success() || failure()
67+
with:
68+
name: test report
69+
path: ./*/TestResults/*.trx
70+
reporter: dotnet-trx
71+
72+
publish:
73+
if: github.event_name == 'release' && github.event.action == 'published' && github.event.release.tag_name
74+
needs: [test]
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v4
78+
- name: Download artifacts
79+
uses: actions/download-artifact@v4
80+
with:
81+
name: binaries
82+
- name: Upload release artifacts
83+
run: gh release upload ${{ github.event.release.tag_name }} ./*/bin/${BUILD_CONFIGURATION}/*.nupkg ./*/bin/${BUILD_CONFIGURATION}/*.snupkg
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
- name: Setup .NET
87+
uses: actions/setup-dotnet@v4
88+
with:
89+
dotnet-version: 10.0.x
90+
- name: Publish NuGet package
91+
run: dotnet nuget push ./*/bin/${BUILD_CONFIGURATION}/*.nupkg --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json

0 commit comments

Comments
 (0)