Skip to content

Commit

Permalink
introduce decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestockdale committed Sep 30, 2019
1 parent 63cc9c6 commit eb9d8dc
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ nuget/lib/
/.vs/fitSharp/v15/Server/sqlite3
.idea/
/source/netcore/**/*.cs
/binary/tools/dbfit/
3 changes: 2 additions & 1 deletion source/fitSharp/Fit/Engine/CellProcessorExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2011 Syterra Software Inc. All rights reserved.
// Copyright © 2019 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.
Expand All @@ -8,6 +8,7 @@
namespace fitSharp.Fit.Engine {
public static class CellProcessorExtension {
public static V Get<V>(this CellProcessor processor) where V: new() { return processor.Memory.GetItem<V>(); }
public static V ItemOf<V>(this CellProcessor processor) { return processor.Memory.ItemOf<V>(); }

public static void Check(this CellProcessor processor, object systemUnderTest, Tree<Cell> memberName, Tree<Cell> parameters, Tree<Cell> expectedCell) {
processor.Operate<CheckOperator>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.

using System;
using fitSharp.Machine.Model;

namespace fitSharp.Fit.Engine {
public class FitSettings: Copyable {
public RunTest RunTest;
public Copyable Copy() {
return new FitSettings {RunTest = RunTest};
}
public interface DecorateElement {
TypedValue Decorate(Tree<Cell> element, Func<TypedValue> action);
}
}
15 changes: 15 additions & 0 deletions source/fitSharp/Fit/Engine/DecorateElementDefault.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright © 2019 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (https://opensource.org/licenses/cpl1.0.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.

using System;
using fitSharp.Machine.Model;

namespace fitSharp.Fit.Engine {
public class DecorateElementDefault: DecorateElement {
public TypedValue Decorate(Tree<Cell> element, Func<TypedValue> action) {
return action();
}
}
}
23 changes: 23 additions & 0 deletions source/fitSharp/Fit/Engine/FitEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright © 2019 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (https://opensource.org/licenses/cpl1.0.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.

using fitSharp.Machine.Model;

namespace fitSharp.Fit.Engine {
public class FitEnvironment: Copyable {
public FitEnvironment(CellProcessor processor) {
this.processor = processor;
}

public RunTest RunTest;
public DecorateElement DecorateElement;

public Copyable Copy() {
return new FitEnvironment(processor) {RunTest = RunTest};
}

readonly CellProcessor processor;
}
}
2 changes: 1 addition & 1 deletion source/fitSharp/Fit/Fixtures/StoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Execute() {
}

public void Execute(CellProcessor cellProcessor) {
cellProcessor.Get<FitSettings>().RunTest.Run(cellProcessor, ParsedInput, writer);
cellProcessor.ItemOf<FitEnvironment>().RunTest.Run(cellProcessor, ParsedInput, writer);
if (cellProcessor.TestStatus.SuiteIsAbandoned) abandonSuite();
}

Expand Down
3 changes: 2 additions & 1 deletion source/fitSharp/Fit/Service/CellProcessorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public CellProcessorBase(Memory memory, CellOperators operators): base(memory) {
Memory.GetItem<Symbols>();
Memory.GetItem<Procedures>();

Memory.GetItem<FitSettings>().RunTest = new RunTestDefault();
Memory.Add(new FitEnvironment(this));
Memory.ItemOf<FitEnvironment>().RunTest = new RunTestDefault();

ApplicationUnderTest.AddNamespace("fitSharp.Fit.Fixtures");
}
Expand Down
4 changes: 3 additions & 1 deletion source/fitSharp/Machine/Engine/Memory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 Syterra Software Inc. All rights reserved.
// Copyright © 2019 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.
Expand All @@ -8,6 +8,8 @@

namespace fitSharp.Machine.Engine {
public interface Memory {
T ItemOf<T>();
void Add(object item);
Memory Copy();
void Apply(Action<object> action);
bool HasItem<T>();
Expand Down
14 changes: 11 additions & 3 deletions source/fitSharp/Machine/Engine/TypeDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 Syterra Software Inc. All rights reserved.
// Copyright © 2019 Syterra Software Inc. All rights reserved.
// The use and distribution terms for this software are covered by the Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file license.txt at the root of this distribution. By using this software in any fashion, you are agreeing
// to be bound by the terms of this license. You must not remove this notice, or any other, from this software.
Expand All @@ -10,6 +10,14 @@
namespace fitSharp.Machine.Engine {
public class TypeDictionary: Configuration {

public T ItemOf<T>() {
return (T)items[typeof(T)];
}

public void Add(object item) {
items[item.GetType()] = item;
}

public Memory Copy() {
var copy = new TypeDictionary();
foreach (Type key in items.Keys) {
Expand All @@ -32,11 +40,11 @@ public bool HasItem<T>() {
if (!HasItem<T>()) {
items[typeof(T)] = new T();
}
return (T)items[typeof(T)];
return ItemOf<T>();
}

public Maybe<T> Item<T>() {
return HasItem<T>() ? new Maybe<T>((T) items[typeof(T)]) : Maybe<T>.Nothing;
return HasItem<T>() ? new Maybe<T>(ItemOf<T>()) : Maybe<T>.Nothing;
}

public object GetItem(string typeName) {
Expand Down
4 changes: 3 additions & 1 deletion source/fitSharp/fitSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@
<Compile Include="Fit\Engine\CheckOperator.cs" />
<Compile Include="Fit\Engine\DefaultFlowInterpreter.cs" />
<Compile Include="Fit\Engine\ExecuteOperator.cs" />
<Compile Include="Fit\Engine\FitSettings.cs" />
<Compile Include="Fit\Engine\FitEnvironment.cs" />
<Compile Include="Fit\Engine\FlowRow.cs" />
<Compile Include="Fit\Engine\Interpreter.cs" />
<Compile Include="Fit\Engine\InterpretFlow.cs" />
<Compile Include="Fit\Engine\InvokeSpecialOperator.cs" />
<Compile Include="Fit\Engine\ListMatcher.cs" />
<Compile Include="Fit\Engine\ListMatchStrategy.cs" />
<Compile Include="Fit\Engine\MethodPhrase.cs" />
<Compile Include="Fit\Engine\DecorateElement.cs" />
<Compile Include="Fit\Engine\DecorateElementDefault.cs" />
<Compile Include="Fit\Engine\RunTest.cs" />
<Compile Include="Fit\Engine\StoryTestWriter.cs" />
<Compile Include="Fit\Engine\ValuePhrase.cs" />
Expand Down
2 changes: 1 addition & 1 deletion source/fitSharpTest/NUnit/Fit/IncludeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ [SetUp] public void SetUp() {
}

[Test] public void ParsesAndExecutesIncludedText() {
processor.Get<FitSettings>().RunTest = new MockRunTest();
processor.ItemOf<FitEnvironment>().RunTest = new MockRunTest();
processor.AddOperator(new MockComposeStoryTestString());
var includeTable = new CellTree(new CellTree("include", "string", input));
new Include().Interpret(processor, includeTable);
Expand Down

0 comments on commit eb9d8dc

Please sign in to comment.