Skip to content

Commit

Permalink
Add more test cases and give some ideas for workarounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 committed Nov 14, 2015
1 parent 72346f9 commit a75df0d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 57 deletions.
129 changes: 75 additions & 54 deletions Nodejs/Product/Nodejs/Debugger/Serialization/NodeBacktraceVariable.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,76 @@
//*********************************************************//
// Copyright (c) Microsoft. All rights reserved.
//
// Apache 2.0 License
//
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
//*********************************************************//

using System;
using Microsoft.VisualStudioTools.Project;
using Newtonsoft.Json.Linq;

namespace Microsoft.NodejsTools.Debugger.Serialization {
sealed class NodeBacktraceVariable : INodeVariable {
public NodeBacktraceVariable(NodeStackFrame stackFrame, JToken parameter) {
Utilities.ArgumentNotNull("stackFrame", stackFrame);
Utilities.ArgumentNotNull("parameter", parameter);

JToken value = parameter["value"];
Id = (int)value["ref"];
Parent = null;
StackFrame = stackFrame;
Name = (string)parameter["name"] ?? NodeVariableType.AnonymousVariable;
TypeName = (string)value["type"];
Value = (string)value["value"];
Class = (string)value["className"];
try {
Text = (string)value["text"];
} catch (ArgumentException) {
Text = String.Empty;
}
Attributes = NodePropertyAttributes.None;
Type = NodePropertyType.Normal;
}

public int Id { get; private set; }
public NodeEvaluationResult Parent { get; private set; }
public string Name { get; private set; }
public string TypeName { get; private set; }
public string Value { get; private set; }
public string Class { get; private set; }
public string Text { get; private set; }
public NodePropertyAttributes Attributes { get; private set; }
public NodePropertyType Type { get; private set; }
public NodeStackFrame StackFrame { get; private set; }
}
//*********************************************************//
// Copyright (c) Microsoft. All rights reserved.
//
// Apache 2.0 License
//
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
//*********************************************************//

using System;
using Microsoft.VisualStudioTools.Project;
using Newtonsoft.Json.Linq;

namespace Microsoft.NodejsTools.Debugger.Serialization {
sealed class NodeBacktraceVariable : INodeVariable {
public NodeBacktraceVariable(NodeStackFrame stackFrame, JToken parameter) {
Utilities.ArgumentNotNull("stackFrame", stackFrame);
Utilities.ArgumentNotNull("parameter", parameter);

JToken value = parameter["value"];
Id = (int)value["ref"];
Parent = null;
StackFrame = stackFrame;
Name = (string)parameter["name"] ?? NodeVariableType.AnonymousVariable;
TypeName = (string)value["type"];
Value = GetValue((JValue)value["value"]);
Class = (string)value["className"];
try {
Text = (string)value["text"];
} catch (ArgumentException) {
Text = String.Empty;
}
Attributes = NodePropertyAttributes.None;
Type = NodePropertyType.Normal;
}

public int Id { get; private set; }
public NodeEvaluationResult Parent { get; private set; }
public string Name { get; private set; }
public string TypeName { get; private set; }
public string Value { get; private set; }
public string Class { get; private set; }
public string Text { get; private set; }
public NodePropertyAttributes Attributes { get; private set; }
public NodePropertyType Type { get; private set; }
public NodeStackFrame StackFrame { get; private set; }

/// <summary>
/// Converts the JValue to string.
/// </summary>
/// <param name="value">Value which has to be converted to string representation.</param>
/// <returns>String which represents the value.</returns>
private static string GetValue(JValue value) {
if (value == null) {
return null;
}

if (value.Type == JTokenType.Date) {
var parentValue = value.Parent.ToString();
return parentValue.Replace("\"value\": \"", string.Empty)
.Replace("\"", string.Empty);
// var dateTimeValue = (DateTime)value.Value;
// return dateTimeValue.ToUniversalTime().ToString("s") + "Z";
}

return (string)value;
}
}
}
6 changes: 3 additions & 3 deletions Nodejs/Tests/Core/Debugger/DebuggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ public void TimeStringLocalsTest()
{
LocalsTest(
"TimeStringLocalsTest.js",
3,
expectedLocals: new string[] { "time" },
expectedValues: new string[] { "2015-05-07T22:00:00.000Z" }
6,
expectedLocals: new string[] { "time", "time1", "time2" },
expectedValues: new string[] { "2015-05-07T22:00:00.000Z", "2015-05-07T22:00:00.000", "2015-05-07 22:00:00.000" }
);
}

Expand Down
3 changes: 3 additions & 0 deletions Nodejs/Tests/TestData/DebuggerProject/TimeStringLocalsTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function TimeStringLocals() {
var time = "2015-05-07T22:00:00.000Z";
var time1 = "2015-05-07T22:00:00.000";
var time2 = "2015-05-07 22:00:00.000";

console.log("TimeStringLocals() done");
}

Expand Down

0 comments on commit a75df0d

Please sign in to comment.