Commit 1e96d103 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

add DOLLAR, TRIM, VALUE

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47258 954022d7-b5bf-4e40-9824-e11837661b57
parent 2d15b362
......@@ -37,8 +37,8 @@
<script type="text/javascript" src="../graphics/pdfprinter.js"></script>
<!--TODO: remove test data-->
<script type="text/javascript" src="../offlinedocs/test-workbook9/Editor.js"></script>
<!-- <script type="text/javascript" src="../offlinedocs/empty-workbook.js"></script> -->
<!-- <script type="text/javascript" src="../offlinedocs/test-workbook9/Editor.js"></script> -->
<script type="text/javascript" src="../offlinedocs/test-workbook2.js"></script>
<script type="text/javascript" src="../model/CollaborativeEditing.js"></script>
<script type="text/javascript" src="../model/parserFormula.js"></script>
......
......@@ -248,13 +248,19 @@
test("Test: YEAR",function(){
oParser = new parserFormula("YEAR(2013)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 1909);
if( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 1909);
else
strictEqual( oParser.calculate().getValue(), 1905);
})
test("Test: DAY",function(){
oParser = new parserFormula("DAY(2013)","A1",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 6);
if( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 6);
else
strictEqual( oParser.calculate().getValue(), 5);
})
test("Test: DAY 2",function(){
......@@ -494,5 +500,79 @@
strictEqual( oParser.calculate().getValue(), "#VALUE!");
})
test("Test: \"SUBSTITUTE\"",function(){
oParser = new parserFormula("SUBSTITUTE(\"abcaAabca\",\"a\",\"xx\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "xxbcxxAxxbcxx");
oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\")","B2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "xxbcxxxxxxbcxx");
oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"\",10)","C2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "bcbc");
oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\",3)","C2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "abcaxxabca");
})
test("Test: \"TRIM\"",function(){
oParser = new parserFormula("TRIM(\" abc def \")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "abc def");
})
test("Test: \"DOLLAR\"",function(){
oParser = new parserFormula("DOLLAR(1234.567)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "$1,234.57");
oParser = new parserFormula("DOLLAR(1234.567,-2)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "$1,200");
oParser = new parserFormula("DOLLAR(-1234.567,4)","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "$-1,234.5670");
})
test("Test: \"VALUE\"",function(){
oParser = new parserFormula("VALUE(\"123.456\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 123.456);
oParser = new parserFormula("VALUE(\"$1,000\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "#VALUE!");
oParser = new parserFormula("VALUE(\"23-Mar-2002\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), "#VALUE!");
oParser = new parserFormula("VALUE(\"03-26-2006\")","A2",ws);
ok(oParser.parse());
if( g_bDate1904 )
strictEqual( oParser.calculate().getValue(), 37340);
else
strictEqual( oParser.calculate().getValue(), 38802);
oParser = new parserFormula("VALUE(\"16:48:00\")-VALUE(\"12:17:12\")","A2",ws);
ok(oParser.parse());
strictEqual( oParser.calculate().getValue(), 0.188055555555556);
})
});
......@@ -7117,6 +7117,21 @@ var cFormulaFunction = {
'DOLLAR' : function(){
var r = new cBaseFunction();
r.setName("DOLLAR");
r.setArgumentsMin(1);
r.setArgumentsMax(2);
r.Calculate = function(arg){
var res = cFormulaFunction.TextAndData["FIXED"]().Calculate(arg);
if( res instanceof cError )
return this.value = res;
return this.value = new cString("$"+res.getValue());
}
r.getInfo = function(){
return {
name:this.name,
args:"( number [ , num-decimal ] )"
};
}
return r;
},
'EXACT' : function(){
......@@ -8102,6 +8117,31 @@ var cFormulaFunction = {
'TRIM' : function(){
var r = new cBaseFunction();
r.setName("TRIM");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
var arg0 = arg[0];
if( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first).tocString();
}
else if( arg0 instanceof cArray){
arg0 = arg0.getElement(0).tocString();
}
arg0 = arg0.tocString();
if( arg0 instanceof cError )
return this.value = arg0;
return this.value = new cString( arg0.getValue().replace(/\s/g, function($0, $1, $2){ var r; /\s/.test($2[$1+1]) ? r = "" : r = $2[$1]; return r; }).replace(/^\s|\s$/g,"") )
}
r.getInfo = function(){
return {
name:this.name,
args:"( string )"
};
}
return r;
},
'UPPER' : function(){
......@@ -8132,6 +8172,31 @@ var cFormulaFunction = {
'VALUE' : function(){
var r = new cBaseFunction();
r.setName("VALUE");
r.setArgumentsMin(1);
r.setArgumentsMax(1);
r.Calculate = function(arg){
var arg0 = arg[0];
if ( arg0 instanceof cArea || arg0 instanceof cArea3D ){
arg0 = arg0.cross(arguments[1].first);
}
else if( arg0 instanceof cArray ){
arg0 = arg0.getElementRowCol(0,0);
}
if ( arg0 instanceof cError )
return this.value = arg0;
arg0 = arg0.tocString();
var res = g_oFormatParser.parse(arg0.getValue());
if( res )
return this.value = new cNumber( res.value );
else
return this.value = new cError( cErrorType.wrong_value_type );
}
return r;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment