Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc9aa2c

Browse files
committed
feat(models): add Truncated flag to Line
Bitbucket sets "truncated": true on file lines that exceed the server's maximum line length when browsing a repository path; the Line model dropped the field, silently losing that signal. Add bool? Truncated so callers can detect truncated content. Implements lvermeulen#30.
1 parent d3e1a9b commit fc9aa2c

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
namespace Bitbucket.Net.Models.Core.Projects;
22

3+
/// <summary>
4+
/// A single line of file content returned when browsing a repository path.
5+
/// </summary>
36
public class Line
47
{
8+
/// <summary>
9+
/// The text of the line.
10+
/// </summary>
511
public string? Text { get; init; }
12+
13+
/// <summary>
14+
/// <see langword="true"/> when Bitbucket truncated this line because it exceeded the server's
15+
/// maximum line length; otherwise <see langword="false"/> or <see langword="null"/> when the
16+
/// server does not report truncation.
17+
/// </summary>
18+
public bool? Truncated { get; init; }
619
}

test/Bitbucket.Net.Tests/UnitTests/ModelSerializationTests.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,72 @@ namespace Bitbucket.Net.Tests.UnitTests;
1212

1313
public class ModelSerializationTests
1414
{
15+
#region Line Serialization Tests
16+
17+
[Fact]
18+
public void Line_Deserialization_ReadsTruncatedFlag()
19+
{
20+
var json = """
21+
{
22+
"text": "a very long line that the server truncated",
23+
"truncated": true
24+
}
25+
""";
26+
27+
var line = JsonSerializer.Deserialize(json, BitbucketJsonContext.Default.Line);
28+
29+
Assert.NotNull(line);
30+
Assert.Equal("a very long line that the server truncated", line.Text);
31+
Assert.True(line.Truncated);
32+
}
33+
34+
[Fact]
35+
public void Line_Deserialization_TruncatedNullWhenAbsent()
36+
{
37+
var json = """
38+
{
39+
"text": "short line"
40+
}
41+
""";
42+
43+
var line = JsonSerializer.Deserialize(json, BitbucketJsonContext.Default.Line);
44+
45+
Assert.NotNull(line);
46+
Assert.Equal("short line", line.Text);
47+
Assert.Null(line.Truncated);
48+
}
49+
50+
[Fact]
51+
public void Line_Deserialization_ReadsExplicitFalse()
52+
{
53+
var json = """
54+
{
55+
"text": "untruncated line",
56+
"truncated": false
57+
}
58+
""";
59+
60+
var line = JsonSerializer.Deserialize(json, BitbucketJsonContext.Default.Line);
61+
62+
Assert.NotNull(line);
63+
Assert.False(line.Truncated);
64+
}
65+
66+
[Fact]
67+
public void Line_Serialization_RoundTrips()
68+
{
69+
var line = new Line { Text = "round trip", Truncated = true };
70+
71+
var json = JsonSerializer.Serialize(line, BitbucketJsonContext.Default.Line);
72+
var deserialized = JsonSerializer.Deserialize(json, BitbucketJsonContext.Default.Line);
73+
74+
Assert.NotNull(deserialized);
75+
Assert.Equal(line.Text, deserialized.Text);
76+
Assert.Equal(line.Truncated, deserialized.Truncated);
77+
}
78+
79+
#endregion
80+
1581
#region Project Serialization Tests
1682

1783
[Fact]

0 commit comments

Comments
 (0)