I'm guessing that the problem is the "test2". AFAIK ternary conditionals need to return either boolean TRUE or FALSE, not a string. So if you change it to something like
: class == (\\'test2\\') ? file.href= dir+\\'test2.txt\\' :
that should fix things up, other than not using a reserved word for the variable name issue.
And I'm not sure that those escapes and parentheses are needed, but I guess that depends on what context you're using this in.