Skip to content

Commit

Permalink
fix: increase max line width
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-tihon committed Sep 8, 2024
1 parent 9d31abd commit ea8e293
Show file tree
Hide file tree
Showing 105 changed files with 2,556 additions and 9,637 deletions.
15 changes: 12 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
# top-most EditorConfig file
root = true

# Don't use tabs for indentation.
[*]
# Non-configurable behaviors
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

# Configurable behaviors
# end_of_line = lf - there is no 'auto' with a .editorconfig
indent_style = space
# (Please don't specify an indent_size here; that has too many unintended consequences.)
indent_size = 4
max_line_length = 120

# Code files
[*.{cs,csx,vb,vbx}]
Expand Down Expand Up @@ -204,4 +213,4 @@ csharp_space_between_square_brackets = false
# Blocks are allowed
csharp_prefer_braces = true:silent
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_statements = true
34 changes: 3 additions & 31 deletions Clippit.Tests/Common/ChartUpdaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ public void CU001(string name)
var wmlTemplate = new WmlDocument(templateFile.FullName);

var afterUpdatingDocx = new FileInfo(
Path.Combine(
TempDir,
templateFile.Name.Replace(".docx", "-processed-by-ChartUpdater.docx")
)
Path.Combine(TempDir, templateFile.Name.Replace(".docx", "-processed-by-ChartUpdater.docx"))
);
wmlTemplate.SaveAs(afterUpdatingDocx.FullName);

Expand Down Expand Up @@ -130,29 +127,7 @@ public void CU001(string name)
Values = new[]
{
new double[] { 1, 2, 3, 2, 3, 4, 5, 4, 5, 6, 5, 4, 5, 6, 7, 8, 7, 8, 8, 9 },
new double[]
{
2,
3,
3,
4,
4,
5,
6,
7,
8,
7,
8,
9,
9,
9,
7,
8,
9,
9,
10,
11,
},
new double[] { 2, 3, 3, 4, 4, 5, 6, 7, 8, 7, 8, 9, 9, 9, 7, 8, 9, 9, 10, 11 },
new double[] { 2, 3, 3, 3, 3, 2, 2, 2, 3, 2, 3, 3, 4, 4, 4, 3, 4, 5, 5, 4 },
},
};
Expand All @@ -163,10 +138,7 @@ public void CU001(string name)
var pmlTemplate = new PmlDocument(templateFile.FullName);

var afterUpdatingPptx = new FileInfo(
Path.Combine(
TempDir,
templateFile.Name.Replace(".pptx", "-processed-by-ChartUpdater.pptx")
)
Path.Combine(TempDir, templateFile.Name.Replace(".pptx", "-processed-by-ChartUpdater.pptx"))
);
pmlTemplate.SaveAs(afterUpdatingPptx.FullName);

Expand Down
58 changes: 11 additions & 47 deletions Clippit.Tests/Common/OpenXmlRegexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,7 @@ public void CanReplaceTextWithQuotationMarks()
part.PutXDocument(partDocument);

var content = partDocument.Descendants(W.p);
var regex = new Regex(
$"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}"
);
var regex = new Regex($"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}");
var count = OpenXmlRegex.Replace(content, regex, "‘changed ${words}’", null);

p = partDocument.Descendants(W.p).First();
Expand Down Expand Up @@ -269,17 +267,8 @@ public void CanReplaceTextWithQuotationMarksAndAddTrackedChangesWhenReplacing()
part.PutXDocument(partDocument);

var content = partDocument.Descendants(W.p);
var regex = new Regex(
$"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}"
);
var count = OpenXmlRegex.Replace(
content,
regex,
"‘changed ${words}’",
null,
true,
"John Doe"
);
var regex = new Regex($"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}");
var count = OpenXmlRegex.Replace(content, regex, "‘changed ${words}’", null, true, "John Doe");

p = partDocument.Descendants(W.p).First();
innerText = InnerText(p);
Expand All @@ -290,20 +279,11 @@ public void CanReplaceTextWithQuotationMarksAndAddTrackedChangesWhenReplacing()
innerText
);

Assert.Contains(
p.Elements(W.ins),
e => InnerText(e) == "‘changed normal double quotes’"
);
Assert.Contains(
p.Elements(W.ins),
e => InnerText(e) == "‘changed double angle quotation marks’"
);
Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed normal double quotes’");
Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed double angle quotation marks’");

Assert.Contains(p.Elements(W.del), e => InnerDelText(e) == "“normal double quotes”");
Assert.Contains(
p.Elements(W.del),
e => InnerDelText(e) == "«double angle quotation marks»"
);
Assert.Contains(p.Elements(W.del), e => InnerDelText(e) == "«double angle quotation marks»");
}

[Fact]
Expand All @@ -324,17 +304,8 @@ public void CanReplaceTextWithQuotationMarksAndTrackedChanges()
part.PutXDocument(partDocument);

var content = partDocument.Descendants(W.p);
var regex = new Regex(
$"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}"
);
var count = OpenXmlRegex.Replace(
content,
regex,
"‘changed ${words}’",
null,
true,
"John Doe"
);
var regex = new Regex($"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}");
var count = OpenXmlRegex.Replace(content, regex, "‘changed ${words}’", null, true, "John Doe");

p = partDocument.Descendants(W.p).First();
innerText = InnerText(p);
Expand All @@ -345,14 +316,8 @@ public void CanReplaceTextWithQuotationMarksAndTrackedChanges()
innerText
);

Assert.Contains(
p.Elements(W.ins),
e => InnerText(e) == "‘changed normal double quotes’"
);
Assert.Contains(
p.Elements(W.ins),
e => InnerText(e) == "‘changed double angle quotation marks’"
);
Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed normal double quotes’");
Assert.Contains(p.Elements(W.ins), e => InnerText(e) == "‘changed double angle quotation marks’");
}

[Fact]
Expand Down Expand Up @@ -384,8 +349,7 @@ public void CanReplaceTextWithSymbolsAndTrackedChanges()
ins =>
ins.Descendants(W.sym)
.Any(sym =>
sym.Attribute(W.font).Value == "Wingdings"
&& sym.Attribute(W._char).Value == "F028"
sym.Attribute(W.font).Value == "Wingdings" && sym.Attribute(W._char).Value == "F028"
)
);
}
Expand Down
3 changes: 1 addition & 2 deletions Clippit.Tests/Common/Samples/ChartUpdaterSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public class ChartUpdaterSamples : TestsBase
public ChartUpdaterSamples(ITestOutputHelper log)
: base(log) { }

private static string GetFilePath(string path) =>
Path.Combine("../../../Common/Samples/ChartUpdater/", path);
private static string GetFilePath(string path) => Path.Combine("../../../Common/Samples/ChartUpdater/", path);

[Theory]
[InlineData("Chart-Cached-Data-01.docx")]
Expand Down
8 changes: 2 additions & 6 deletions Clippit.Tests/Common/Samples/MetricsGetterSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class MetricsGetterSamples : TestsBase
public MetricsGetterSamples(ITestOutputHelper log)
: base(log) { }

private static string GetFilePath(string path) =>
Path.Combine("../../../Common/Samples/MetricsGetter/", path);
private static string GetFilePath(string path) => Path.Combine("../../../Common/Samples/MetricsGetter/", path);

[Theory]
[InlineData("ContentControls.docx", false)] // No text from content controls
Expand All @@ -20,10 +19,7 @@ private static string GetFilePath(string path) =>
public void Word(string fileName, bool includeTextInControls)
{
var fi = new FileInfo(GetFilePath(fileName));
var settings = new MetricsGetterSettings
{
IncludeTextInContentControls = includeTextInControls,
};
var settings = new MetricsGetterSettings { IncludeTextInContentControls = includeTextInControls };
var metrics = MetricsGetter.GetMetrics(fi.FullName, settings);
Log.WriteLine(metrics.ToString());
}
Expand Down
32 changes: 6 additions & 26 deletions Clippit.Tests/Common/Samples/OpenXmlRegexSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public class OpenXmlRegexSamples : TestsBase
public OpenXmlRegexSamples(ITestOutputHelper log)
: base(log) { }

private static string GetFilePath(string path) =>
Path.Combine("../../../Common/Samples/OpenXmlRegex/", path);
private static string GetFilePath(string path) => Path.Combine("../../../Common/Samples/OpenXmlRegex/", path);

[Fact]
public void WordSample1()
Expand Down Expand Up @@ -138,17 +137,13 @@ public void WordSample1()

// Replace content using replacement pattern (paragraph 16)
content = xDoc.Descendants(W.p).Skip(15).Take(1);
regex = new Regex(
$"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}"
);
regex = new Regex($"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}");
count = OpenXmlRegex.Replace(content, regex, "‘${words}’", null);
Log.WriteLine("Example #18 Replaced: {0}", count);

// Replace content using replacement pattern in partially inserted text (paragraph 17)
content = xDoc.Descendants(W.p).Skip(16).Take(1);
regex = new Regex(
$"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}"
);
regex = new Regex($"{LeftDoubleQuotationMarks}(?<words>{Words}){RightDoubleQuotationMarks}");
count = OpenXmlRegex.Replace(content, regex, "‘${words}’", null, true, "John Doe");
Log.WriteLine("Example #19 Replaced: {0}", count);

Expand All @@ -173,12 +168,7 @@ public void WordSample1()
// Recognize tabs and insert line breaks (paragraph 20).
content = xDoc.Descendants(W.p).Skip(19).Take(1);
regex = new Regex($@"([1-9])\.{UnicodeMapper.HorizontalTabulation}");
count = OpenXmlRegex.Replace(
content,
regex,
$"Article $1{UnicodeMapper.CarriageReturn}",
null
);
count = OpenXmlRegex.Replace(content, regex, $"Article $1{UnicodeMapper.CarriageReturn}", null);
Log.WriteLine("Example #22 Replaced: {0}", count);

// Recognize and remove line breaks (paragraph 21)
Expand Down Expand Up @@ -222,18 +212,8 @@ public void WordSample1()
$"{newPhone} (replaced with new phone)",
null
);
count += OpenXmlRegex.Replace(
paras,
new Regex($"({pencil})"),
"$1 (same pencil)",
null
);
count += OpenXmlRegex.Replace(
paras,
new Regex($"({spider})"),
"$1 (same spider)",
null
);
count += OpenXmlRegex.Replace(paras, new Regex($"({pencil})"), "$1 (same pencil)", null);
count += OpenXmlRegex.Replace(paras, new Regex($"({spider})"), "$1 (same spider)", null);
Log.WriteLine("Example #25 Replaced: {0}", count);

wDoc.MainDocumentPart.PutXDocument();
Expand Down
53 changes: 12 additions & 41 deletions Clippit.Tests/Common/Samples/TextReplacerSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ public class TextReplacerSamples : TestsBase
public TextReplacerSamples(ITestOutputHelper log)
: base(log) { }

private static string GetFilePath(string path) =>
Path.Combine("../../../Common/Samples/TextReplacer/", path);
private static string GetFilePath(string path) => Path.Combine("../../../Common/Samples/TextReplacer/", path);

[Theory]
[InlineData("PowerPoint/Test01.pptx")]
[InlineData("PowerPoint/Test02.pptx")]
[InlineData("PowerPoint/Test03.pptx")]
public void PowerPoint(string filePath)
{
var outFile = Path.Combine(
TempDir,
Path.GetFileName(filePath).Replace(".pptx", "out.pptx")
);
var outFile = Path.Combine(TempDir, Path.GetFileName(filePath).Replace(".pptx", "out.pptx"));
File.Copy(GetFilePath(filePath), outFile);
using var pDoc = PresentationDocument.Open(outFile, true);
TextReplacer.SearchAndReplace(pDoc, "Hello", "Goodbye", true);
Expand All @@ -37,60 +33,35 @@ public void Word()
foreach (var file in di2.GetFiles("*.docx"))
file.CopyTo(Path.Combine(TempDir, file.Name));

using (
var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test01.docx"), true)
)
using (var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test01.docx"), true))
TextReplacer.SearchAndReplace(doc, "the", "this", false);

try
{
using var doc = WordprocessingDocument.Open(
Path.Combine(TempDir, "Test02.docx"),
true
);
using var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test02.docx"), true);
TextReplacer.SearchAndReplace(doc, "the", "this", false);
}
catch (Exception) { }

try
{
using var doc = WordprocessingDocument.Open(
Path.Combine(TempDir, "Test03.docx"),
true
);
using var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test03.docx"), true);
TextReplacer.SearchAndReplace(doc, "the", "this", false);
}
catch (Exception) { }

using (
var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test04.docx"), true)
)
using (var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test04.docx"), true))
TextReplacer.SearchAndReplace(doc, "the", "this", true);
using (
var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test05.docx"), true)
)
using (var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test05.docx"), true))
TextReplacer.SearchAndReplace(doc, "is on", "is above", true);
using (
var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test06.docx"), true)
)
using (var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test06.docx"), true))
TextReplacer.SearchAndReplace(doc, "the", "this", false);
using (
var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test07.docx"), true)
)
using (var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test07.docx"), true))
TextReplacer.SearchAndReplace(doc, "the", "this", true);
using (
var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test08.docx"), true)
)
using (var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test08.docx"), true))
TextReplacer.SearchAndReplace(doc, "the", "this", true);
using (
var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test09.docx"), true)
)
TextReplacer.SearchAndReplace(
doc,
"===== Replace this text =====",
"***zzz***",
true
);
using (var doc = WordprocessingDocument.Open(Path.Combine(TempDir, "Test09.docx"), true))
TextReplacer.SearchAndReplace(doc, "===== Replace this text =====", "***zzz***", true);
}
}
}
Loading

0 comments on commit ea8e293

Please sign in to comment.