Last active
August 29, 2015 14:03
-
-
Save sakura-crowd/cf43df70ff1d946640af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('sakuraCrowd.linkById', function() { | |
it("参照オブジェクトを参照先オブジェクトに変換する", function() { | |
var target = [ | |
{"id":"id1", "value":10}, | |
{"$ref":"id1"} | |
]; | |
sakuraCrowd.linkById(target); | |
expect(target.length).toEqual(2); | |
expect(target[0]).toBe(target[1]); | |
}); | |
it("循環参照を検出したら該当する JsonPath を返して警告する", function() { | |
var target = [ | |
{"id":"id1", "value":10, "other":{"$ref":"id2"}}, | |
{"id":"id2", "other":{"$ref":"id1"}} | |
]; | |
var path = "$[0].other.other"; | |
expect(sakuraCrowd.linkById.bind(null, target)).toThrow("循環参照です。" + path); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
オブジェクトのプロパティ値を ID 文字列でリンクさせるための関数の jasmine 用のテストケースです。
TMX に定義したオブジェクトの設定で、外部のオブジェクトを簡単に指定するために作りました。
$ref プロパティを持つオブジェクトを参照オブジェクトと呼びます。
id プロパティを持つオブジェクトは、外部から参照オブジェクト {$ref : id} をプロパティの値に設定することでリンクすることができます。
上記の1番目の例では、$[1] の値は参照オブジェクトなので、 $[0] のオブジェクトに置換されます。
循環参照を避けるため、自身またはそれよりルートのオブジェクトにリンクすることはできません。
エラーの場合は、 JsonPath の絶対パスで発生した場所を表します。