forked from microsoft/kiota
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRubyPathSegmenterTests.cs
More file actions
78 lines (68 loc) · 3.37 KB
/
Copy pathRubyPathSegmenterTests.cs
File metadata and controls
78 lines (68 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.Linq;
using Kiota.Builder.CodeDOM;
using Kiota.Builder.PathSegmenters;
using Xunit;
namespace Kiota.Builder.Tests.PathSegmenters
{
public class RubyPathSegmenterTests
{
private readonly RubyPathSegmenter segmenter;
public RubyPathSegmenterTests()
{
segmenter = new RubyPathSegmenter("/tmp/kiota-sample", "client");
}
[Fact]
public void RubyPathSegmenterGeneratesCorrectFileName()
{
var rootNamespace = CodeNamespace.InitRootNamespace();
var classExample = rootNamespace.AddClass(new CodeClass
{
Name = "testClass"
}).First();
Assert.Equal("test_class", segmenter.NormalizeFileName(classExample));
}
[Fact]
public void DisambiguatesEnumsThatSnakeCaseToTheSameFileName()
{
// the github description declares both a top level status enum and an inline one on the
// parent schema; snake casing collapses them onto one path, so one silently overwrote
// the other and the models barrel required the same file twice
var rootNamespace = CodeNamespace.InitRootNamespace();
var ns = rootNamespace.AddNamespace("client.models");
var withSeparator = ns.AddEnum(new CodeEnum { Name = "codeScanningVariantAnalysis_status" }).First();
var withoutSeparator = ns.AddEnum(new CodeEnum { Name = "codeScanningVariantAnalysisStatus" }).First();
var first = segmenter.NormalizeFileName(withSeparator);
var second = segmenter.NormalizeFileName(withoutSeparator);
Assert.NotEqual(first, second);
}
[Fact]
public void DisambiguatesAClassAndAnEnumSharingAFileName()
{
var rootNamespace = CodeNamespace.InitRootNamespace();
var ns = rootNamespace.AddNamespace("client.models");
var model = ns.AddClass(new CodeClass { Name = "SomeModel", Kind = CodeClassKind.Model }).First();
var enumeration = ns.AddEnum(new CodeEnum { Name = "some_model" }).First();
Assert.NotEqual(segmenter.NormalizeFileName(model), segmenter.NormalizeFileName(enumeration));
}
[Fact]
public void KeepsTheFileNameStableWhenThereIsNoCollision()
{
var rootNamespace = CodeNamespace.InitRootNamespace();
var ns = rootNamespace.AddNamespace("client.models");
var only = ns.AddClass(new CodeClass { Name = "someModel", Kind = CodeClassKind.Model }).First();
ns.AddClass(new CodeClass { Name = "otherModel", Kind = CodeClassKind.Model });
Assert.Equal("some_model", segmenter.NormalizeFileName(only));
}
[Fact]
public void ReturnsTheSameNameForRepeatedCalls()
{
// the writer resolves the require path and the file writer resolves the output path
// through separate calls, so they have to agree
var rootNamespace = CodeNamespace.InitRootNamespace();
var ns = rootNamespace.AddNamespace("client.models");
ns.AddEnum(new CodeEnum { Name = "codeScanningVariantAnalysis_status" });
var second = ns.AddEnum(new CodeEnum { Name = "codeScanningVariantAnalysisStatus" }).First();
Assert.Equal(segmenter.NormalizeFileName(second), segmenter.NormalizeFileName(second));
}
}
}