Skip to content

Commit

Permalink
Single file namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
anpetroc committed Dec 3, 2023
1 parent 562fd3b commit 0938da7
Show file tree
Hide file tree
Showing 22 changed files with 2,262 additions and 2,345 deletions.
105 changes: 52 additions & 53 deletions src/PAModel/PAConvert/Parser/SourceLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,69 @@
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.PowerPlatform.Formulas.Tools.IR
namespace Microsoft.PowerPlatform.Formulas.Tools.IR;

internal struct SourceLocation
{
internal struct SourceLocation
public readonly int StartLine;
public readonly int StartChar;
public readonly int EndLine;
public readonly int EndChar;
public readonly string FileName;

// Indices into file are 1-based.
public SourceLocation(int startLine, int startChar, int endLine, int endChar, string fileName)
{
public readonly int StartLine;
public readonly int StartChar;
public readonly int EndLine;
public readonly int EndChar;
public readonly string FileName;
StartLine = startLine;
StartChar = startChar;
EndLine = endLine;
EndChar = endChar;
FileName = fileName;
}

// Indices into file are 1-based.
public SourceLocation(int startLine, int startChar, int endLine, int endChar, string fileName)
{
StartLine = startLine;
StartChar = startChar;
EndLine = endLine;
EndChar = endChar;
FileName = fileName;
}
public static SourceLocation FromFile(string filename)
{
return new SourceLocation(0, 0, 0, 0, filename);
}

public static SourceLocation FromFile(string filename)
{
return new SourceLocation(0, 0, 0, 0, filename);
}
public override string ToString()
{
return $"{FileName}:{StartLine},{StartChar}-{EndLine},{EndChar}";
}

public override string ToString()
{
return $"{FileName}:{StartLine},{StartChar}-{EndLine},{EndChar}";
}
public static SourceLocation FromChildren(List<SourceLocation> locations)
{
SourceLocation minLoc = locations.First(), maxLoc = locations.First();

public static SourceLocation FromChildren(List<SourceLocation> locations)
foreach (var loc in locations)
{
SourceLocation minLoc = locations.First(), maxLoc = locations.First();

foreach (var loc in locations)
if (loc.StartLine < minLoc.StartLine ||
(loc.StartLine == minLoc.StartLine && loc.StartChar < minLoc.StartChar))
{
if (loc.StartLine < minLoc.StartLine ||
(loc.StartLine == minLoc.StartLine && loc.StartChar < minLoc.StartChar))
{
minLoc = loc;
}
if (loc.EndLine > maxLoc.EndLine ||
(loc.EndLine == minLoc.EndLine && loc.EndChar > minLoc.EndChar))
{
maxLoc = loc;
}
minLoc = loc;
}
if (loc.EndLine > maxLoc.EndLine ||
(loc.EndLine == minLoc.EndLine && loc.EndChar > minLoc.EndChar))
{
maxLoc = loc;
}

return new SourceLocation(minLoc.StartLine, minLoc.StartChar, maxLoc.EndLine, maxLoc.EndChar, maxLoc.FileName);
}

public override bool Equals(object obj)
{
return obj is SourceLocation other &&
other.FileName == FileName &&
other.StartChar == StartChar &&
other.StartLine == StartLine &&
other.EndChar == EndChar &&
other.EndLine == EndLine;
}
return new SourceLocation(minLoc.StartLine, minLoc.StartChar, maxLoc.EndLine, maxLoc.EndChar, maxLoc.FileName);
}

public override int GetHashCode()
{
return (FileName, StartChar, EndChar, StartLine, EndLine).GetHashCode();
}
public override bool Equals(object obj)
{
return obj is SourceLocation other &&
other.FileName == FileName &&
other.StartChar == StartChar &&
other.StartLine == StartLine &&
other.EndChar == EndChar &&
other.EndLine == EndLine;
}

public override int GetHashCode()
{
return (FileName, StartChar, EndChar, StartLine, EndLine).GetHashCode();
}
}
135 changes: 65 additions & 70 deletions src/PAModelTests/AppTestsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,87 @@
// Licensed under the MIT License.

using Microsoft.PowerPlatform.Formulas.Tools;
using Microsoft.PowerPlatform.Formulas.Tools.Utility;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;

namespace PAModelTests
namespace PAModelTests;

// DataSources Tests
[TestClass]
public class AppTestsTest
{
// DataSources Tests
[TestClass]
public class AppTestsTest
// Validates that the App can be repacked after deleting the EditorState files, when the app contains app tests which refer to screens.
[DataTestMethod]
[DataRow("TestStudio_Test.msapp")]
public void TestPackWhenEditorStateIsDeleted(string appName)
{
// Validates that the App can be repacked after deleting the EditorState files, when the app contains app tests which refer to screens.
[DataTestMethod]
[DataRow("TestStudio_Test.msapp")]
public void TestPackWhenEditorStateIsDeleted(string appName)
var root = Path.Combine(Environment.CurrentDirectory, "Apps", appName);
Assert.IsTrue(File.Exists(root));

(var msapp, var errors) = CanvasDocument.LoadFromMsapp(root);
errors.ThrowOnErrors();

using (var tempDir = new TempDir())
{
var root = Path.Combine(Environment.CurrentDirectory, "Apps", appName);
Assert.IsTrue(File.Exists(root));
string outSrcDir = tempDir.Dir;

// Save to sources
msapp.SaveToSources(outSrcDir);

(var msapp, var errors) = CanvasDocument.LoadFromMsapp(root);
errors.ThrowOnErrors();
// Delete Entropy directory
var editorStatePath = Path.Combine(outSrcDir, "Src", "EditorState");
if (Directory.Exists(editorStatePath))
{
Directory.Delete(editorStatePath, true);
}

using (var tempDir = new TempDir())
// Load app from the sources after deleting the entropy
var app = SourceSerializer.LoadFromSource(outSrcDir, new ErrorContainer());

using (var tempFile = new TempFile())
{
string outSrcDir = tempDir.Dir;

// Save to sources
msapp.SaveToSources(outSrcDir);

// Delete Entropy directory
var editorStatePath = Path.Combine(outSrcDir, "Src", "EditorState");
if (Directory.Exists(editorStatePath))
{
Directory.Delete(editorStatePath, true);
}

// Load app from the sources after deleting the entropy
var app = SourceSerializer.LoadFromSource(outSrcDir, new ErrorContainer());

using (var tempFile = new TempFile())
{
// Repack the app
MsAppSerializer.SaveAsMsApp(app, tempFile.FullPath, new ErrorContainer());
}
// Repack the app
MsAppSerializer.SaveAsMsApp(app, tempFile.FullPath, new ErrorContainer());
}
}
}

// Validates that the App can be repacked after deleting the Entropy files, when the app contains app tests which refer to screens.
[DataTestMethod]
[DataRow("TestStudio_Test.msapp")]
public void TestPackWhenEntropyIsDeleted(string appName)
// Validates that the App can be repacked after deleting the Entropy files, when the app contains app tests which refer to screens.
[DataTestMethod]
[DataRow("TestStudio_Test.msapp")]
public void TestPackWhenEntropyIsDeleted(string appName)
{
var root = Path.Combine(Environment.CurrentDirectory, "Apps", appName);
Assert.IsTrue(File.Exists(root));

(var msapp, var errors) = CanvasDocument.LoadFromMsapp(root);
errors.ThrowOnErrors();

using (var tempDir = new TempDir())
{
var root = Path.Combine(Environment.CurrentDirectory, "Apps", appName);
Assert.IsTrue(File.Exists(root));
string outSrcDir = tempDir.Dir;

// Save to sources
msapp.SaveToSources(outSrcDir);

(var msapp, var errors) = CanvasDocument.LoadFromMsapp(root);
errors.ThrowOnErrors();
// Delete Entropy directory
var entropyPath = Path.Combine(outSrcDir, "Entropy");
if (Directory.Exists(entropyPath))
{
Directory.Delete(entropyPath, true);
}

using (var tempDir = new TempDir())
// Load app from the sources after deleting the entropy
var app = SourceSerializer.LoadFromSource(outSrcDir, new ErrorContainer());

using (var tempFile = new TempFile())
{
string outSrcDir = tempDir.Dir;

// Save to sources
msapp.SaveToSources(outSrcDir);

// Delete Entropy directory
var entropyPath = Path.Combine(outSrcDir, "Entropy");
if (Directory.Exists(entropyPath))
{
Directory.Delete(entropyPath, true);
}

// Load app from the sources after deleting the entropy
var app = SourceSerializer.LoadFromSource(outSrcDir, new ErrorContainer());

using (var tempFile = new TempFile())
{
// Repack the app
MsAppSerializer.SaveAsMsApp(app, tempFile.FullPath, new ErrorContainer());

// re-unpack should succeed
(var msapp1, var errors1) = CanvasDocument.LoadFromMsapp(tempFile.FullPath);
msapp1.SaveToSources(new TempDir().Dir);
}
// Repack the app
MsAppSerializer.SaveAsMsApp(app, tempFile.FullPath, new ErrorContainer());

// re-unpack should succeed
(var msapp1, var errors1) = CanvasDocument.LoadFromMsapp(tempFile.FullPath);
msapp1.SaveToSources(new TempDir().Dir);
}
}
}
Expand Down
Loading

0 comments on commit 0938da7

Please sign in to comment.