1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 02:25:41 +00:00

Compare commits

...

9 Commits

4 changed files with 50 additions and 33 deletions

View File

@ -1,50 +1,56 @@
name: Build name: SonarCloud
on: on:
push: push:
branches: branches:
- main - main
workflow_dispatch: workflow_dispatch:
pull_request: pull_request:
types: [opened, synchronize, reopened] types: [ opened, synchronize, reopened ]
jobs: jobs:
build: sonarcloud:
name: Build name: SonarCloud Analysis
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- name: Set up JDK 11 - name: Set up JDK 17
uses: actions/setup-java@v1 uses: actions/setup-java@v3
with: with:
java-version: 1.11 java-version: 17
distribution: 'zulu'
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Cache SonarCloud packages - name: Cache SonarCloud packages
uses: actions/cache@v1 uses: actions/cache@v3
with: with:
path: ~\sonar\cache path: ~\sonar\cache
key: ${{ runner.os }}-sonar key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner - name: Cache SonarCloud scanner
id: cache-sonar-scanner id: cache-sonar-scanner
uses: actions/cache@v1 uses: actions/cache@v3
with: with:
path: .\.sonar\scanner path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner - name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell shell: powershell
run: | run: |
New-Item -Path .\.sonar\scanner -ItemType Directory New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Build and analyze - name: Build and analyze
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell shell: powershell
run: | run: |
dotnet tool install JetBrains.dotCover.GlobalTool -g .\.sonar\scanner\dotnet-sonarscanner begin /k:"oliverbooth_X10D" /o:"oliverbooth" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
.\.sonar\scanner\dotnet-sonarscanner begin /k:"oliverbooth_X10D" /o:"oliverbooth" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths=dotCover.Output.html
dotnet build --no-incremental dotnet build --no-incremental
dotnet dotcover test --dcReportType=HTML dotnet dotcover test --dcReportType=HTML
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

View File

@ -8,12 +8,15 @@ internal class CharTests
{ {
[Test] [Test]
public void IsEmoji_ShouldReturnTrue_GivenBasicEmoji() public void IsEmoji_ShouldReturnTrue_GivenBasicEmoji()
{
Assert.Multiple(() =>
{ {
Assert.That('✂'.IsEmoji()); Assert.That('✂'.IsEmoji());
Assert.That('✅'.IsEmoji()); Assert.That('✅'.IsEmoji());
Assert.That('❎'.IsEmoji()); Assert.That('❎'.IsEmoji());
Assert.That(''.IsEmoji()); Assert.That(''.IsEmoji());
Assert.That(''.IsEmoji()); Assert.That(''.IsEmoji());
});
} }
[Test] [Test]
@ -26,7 +29,7 @@ internal class CharTests
} }
[Test] [Test]
public void RepeatShouldBeCorrect() public void Repeat_ShouldReturnRepeatedCharacter_GivenValidCount()
{ {
const string expected = "aaaaaaaaaa"; const string expected = "aaaaaaaaaa";
string actual = 'a'.Repeat(10); string actual = 'a'.Repeat(10);
@ -35,22 +38,22 @@ internal class CharTests
} }
[Test] [Test]
public void RepeatOneCountShouldBeLength1String() public void Repeat_ShouldReturnSingleCharString_GivenCount1()
{ {
string repeated = 'a'.Repeat(1); string repeated = 'a'.Repeat(1);
Assert.That(repeated.Length, Is.EqualTo(1)); Assert.That(repeated, Has.Length.EqualTo(1));
Assert.That(repeated, Is.EqualTo("a")); Assert.That(repeated, Is.EqualTo("a"));
} }
[Test] [Test]
public void RepeatZeroCountShouldBeEmpty() public void Repeat_ShouldReturnEmptyString_GivenCount0()
{ {
Assert.That('a'.Repeat(0), Is.EqualTo(string.Empty)); Assert.That('a'.Repeat(0), Is.EqualTo(string.Empty));
} }
[Test] [Test]
public void RepeatNegativeCountShouldThrow() public void Repeat_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount()
{ {
Assert.Throws<ArgumentOutOfRangeException>(() => 'a'.Repeat(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => _ = 'a'.Repeat(-1));
} }
} }

View File

@ -39,13 +39,19 @@ internal class MarkdownTests
[Test] [Test]
public void MDCodeBlock_ShouldReturnCodeBlockText_GivenText() public void MDCodeBlock_ShouldReturnCodeBlockText_GivenText()
{ {
Assert.That("Hello, world!".MDCodeBlock(), Is.EqualTo($"```{Environment.NewLine}Hello, world!{Environment.NewLine}```")); var expected = $"```{Environment.NewLine}Hello, world!{Environment.NewLine}```";
string actual = "Hello, world!".MDCodeBlock();
Assert.That(actual, Is.EqualTo(expected));
} }
[Test] [Test]
public void MDCodeBlock_ShouldReturnCodeBlockText_GivenTextAndLanguage() public void MDCodeBlock_ShouldReturnCodeBlockText_GivenTextAndLanguage()
{ {
Assert.That("Hello, world!".MDCodeBlock("csharp"), Is.EqualTo($"```csharp{Environment.NewLine}Hello, world!{Environment.NewLine}```")); var expected = $"```csharp{Environment.NewLine}Hello, world!{Environment.NewLine}```";
string actual = "Hello, world!".MDCodeBlock("csharp");
Assert.That(actual, Is.EqualTo(expected));
} }
[Test] [Test]
@ -63,6 +69,8 @@ internal class MarkdownTests
[Test] [Test]
public void MDHeading_ShouldReturnHeadingText_GivenText() public void MDHeading_ShouldReturnHeadingText_GivenText()
{
Assert.Multiple(() =>
{ {
Assert.That("Hello, world!".MDHeading(1), Is.EqualTo("# Hello, world!")); Assert.That("Hello, world!".MDHeading(1), Is.EqualTo("# Hello, world!"));
Assert.That("Hello, world!".MDHeading(2), Is.EqualTo("## Hello, world!")); Assert.That("Hello, world!".MDHeading(2), Is.EqualTo("## Hello, world!"));
@ -70,6 +78,7 @@ internal class MarkdownTests
Assert.That("Hello, world!".MDHeading(4), Is.EqualTo("#### Hello, world!")); Assert.That("Hello, world!".MDHeading(4), Is.EqualTo("#### Hello, world!"));
Assert.That("Hello, world!".MDHeading(5), Is.EqualTo("##### Hello, world!")); Assert.That("Hello, world!".MDHeading(5), Is.EqualTo("##### Hello, world!"));
Assert.That("Hello, world!".MDHeading(6), Is.EqualTo("###### Hello, world!")); Assert.That("Hello, world!".MDHeading(6), Is.EqualTo("###### Hello, world!"));
});
} }
[Test] [Test]

View File

@ -911,8 +911,7 @@ public static class StringExtensions
/// </summary> /// </summary>
/// <param name="value">The string to repeat.</param> /// <param name="value">The string to repeat.</param>
/// <param name="count">The repeat count.</param> /// <param name="count">The repeat count.</param>
/// <returns>A string containing <paramref name="value" /> repeated <paramref name="count" /> times. /// <returns>A string containing <paramref name="value" /> repeated <paramref name="count" /> times.</returns>
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
[Pure] [Pure]
[MethodImpl(CompilerResources.MethodImplOptions)] [MethodImpl(CompilerResources.MethodImplOptions)]