diff --git a/src/SPDXLicenseMatcher/FastLicenseMatcher.cs b/src/SPDXLicenseMatcher/FastLicenseMatcher.cs index 1173f511..8b17f4eb 100644 --- a/src/SPDXLicenseMatcher/FastLicenseMatcher.cs +++ b/src/SPDXLicenseMatcher/FastLicenseMatcher.cs @@ -32,7 +32,6 @@ public class FastLicenseMatcher : ILicenseMatcher private static readonly Regex BEGIN_OPTIONAL_COMMENT_PATTERN = new Regex("^\\s*<>\\s*" + START_COMMENT_CHAR_PATTERN, RegexOptions.Compiled); #pragma warning restore IDE1006 - private readonly IImmutableDictionary _templateInstructions; public FastLicenseMatcher(IDictionary licenses) diff --git a/tests/SPDXLicenseMatcher.Test/LicenseMatcherTest.cs b/tests/SPDXLicenseMatcher.Test/LicenseMatcherTest.cs index c4627eb6..0430469a 100644 --- a/tests/SPDXLicenseMatcher.Test/LicenseMatcherTest.cs +++ b/tests/SPDXLicenseMatcher.Test/LicenseMatcherTest.cs @@ -51,6 +51,23 @@ public static IEnumerable> GetCases() } } + public static class RealWorldLicenses + { + private const string PREFIX = "SPDXLicenseMatcher.Test.RealLicenses."; + private static readonly int s_prefixLength = PREFIX.Length; + public static IEnumerable> GetCases() + { + var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); + foreach (string name in executingAssembly.GetManifestResourceNames().Where(n => n.StartsWith(PREFIX)).Where(n => n.EndsWith("txt"))) + { + string fileName = name.Substring(s_prefixLength); + string expectedIdentifier = fileName.Split("__")[0]; + using var reader = new StreamReader(executingAssembly.GetManifestResourceStream(name)!); + yield return () => new Case(expectedIdentifier, reader.ReadToEnd()); + } + } + } + #pragma warning disable S125 // Sections of code should not be commented out /* [Test] @@ -78,5 +95,12 @@ public async Task Fast_License_Matcher_Should_Not_Pick_A_License(string licenseT { await Assert.That(FastlicenseMatcher.Match(licenseText)).IsEmpty(); } + + [Test] + [MethodDataSource(typeof(RealWorldLicenses), nameof(RealWorldLicenses.GetCases))] + public async Task Fast_License_Matcher_Should_Mattch_Real_World_Licenses(Case @case) + { + await Assert.That(FastlicenseMatcher.Match(@case.Content)).Contains(@case.Identifier); + } } } diff --git a/tests/SPDXLicenseMatcher.Test/NonSpdxTestLicenses/AlmostMit.txt b/tests/SPDXLicenseMatcher.Test/NonSpdxTestLicenses/AlmostMit.txt deleted file mode 100644 index bf9dace0..00000000 --- a/tests/SPDXLicenseMatcher.Test/NonSpdxTestLicenses/AlmostMit.txt +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) 2025 John Doe - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/tests/SPDXLicenseMatcher.Test/RealLicenses/MIT__fromOpensource.txt b/tests/SPDXLicenseMatcher.Test/RealLicenses/MIT__fromOpensource.txt new file mode 100644 index 00000000..5e9b8194 --- /dev/null +++ b/tests/SPDXLicenseMatcher.Test/RealLicenses/MIT__fromOpensource.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2025 John Doe + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/tests/SPDXLicenseMatcher.Test/SPDXLicenseMatcher.Test.csproj b/tests/SPDXLicenseMatcher.Test/SPDXLicenseMatcher.Test.csproj index 069920a2..a4243a29 100644 --- a/tests/SPDXLicenseMatcher.Test/SPDXLicenseMatcher.Test.csproj +++ b/tests/SPDXLicenseMatcher.Test/SPDXLicenseMatcher.Test.csproj @@ -29,9 +29,7 @@ - - - +