Add a test to show that threshold 40 would corrupt

If we set `ENCODING_CONFIDENCE_THRESHOLD` to 40,
this test case would not pass. If we raise to 50,
this would pass.

Note that if in the future rugged didn't return
corrupt data, this would be less relevant. But still
icu recommend the threshold to be 50, we should just
stick with 50.
This commit is contained in:
Lin Jen-Shin 2017-08-08 19:05:40 +08:00
parent b8ba0efed0
commit d831e8e1d0
3 changed files with 94 additions and 0 deletions

42
spec/fixtures/encoding/Japanese.md vendored Normal file
View File

@ -0,0 +1,42 @@
+++
date = "2017-05-21T13:05:07+09:00"
title = "レイヤ"
weight = 10
+++
## このチュートリアルで扱う内容
1. Redactedにおける2D開発でのレイヤの基本的な概要
2. スクリーン上のスプライトの順序付け方法
### Redactedにおける2D開発でのレイヤの基本的な概要
2Dにおいてはz軸が存在しないため、シーン内要素の描画順を制御するためには代替となる仕組みが必要です。
Redactedでは**レイヤ**における**zIndex**属性を制御可能にすることで、この課題を解決しています。
**デフォルトでは、zIndexは0となりオブジェクトはレイヤに追加された順番に描画されます。**
レイヤにはいくつかの重要な特性があります。
* レイヤにはレイヤ化されたオブジェクトのみを含めることができます。(**3Dモデルは絶対に追加しないでください**
* レイヤはレイヤ化されたオブジェクトです。(したがって、レイヤには他のレイヤを含めることができます)
* レイヤ化されたオブジェクトは、最大で1つのレイヤに属すことができます。
レイヤを直接初期化することはできませんが、その派生クラスは初期化することが可能です。**Scene2D**と**コンテナ**は、**レイヤ**から派生する2つの主なオブジェクトです。すべての初期化createContainer、instantiate、...はレイヤ上で行われます。つまり、2Dで初期化されるすべてのオブジェクトは、zIndexプロパティを持つレイヤ化されたオブジェクトです。
**zIndexはグローバルではありません!**
CSSとは異なり、zIndexはすべてのオブジェクトに対してグローバルではありません。zIndexプロパティは親レイヤに対してローカルです。詳細につきましては、コンテナチュートリアルで説明しています。 [TODO: Link]。
### スクリーン上のスプライトの順序付け方法
これまで学んだことを生かして、画面にスプライトを表示して、zIndexの設定をしてみましょう
* まず、最初に (A,B,C) スプライトを生成します。
* スプライトAをシーンに追加しますzIndex = 0、標準色
* スプライトBをシーン2に追加すると、**スプライトAの上に**表示されますzIndex = 0、赤色
* 最後にスプライトCをシーンに追加します青色が、スプライトのzIndexを-1に設定すると、スプライトはAとBの後側に表示されます。
{{< code "static/tutorials/layers.html" >}}
### ソースコード全体
```js
{{< snippet "static/tutorials/layers.html" >}}
```

View File

@ -30,6 +30,50 @@ describe Gitlab::EncodingHelper do
it 'leaves binary string as is' do
expect(ext_class.encode!(binary_string)).to eq(binary_string)
end
context 'with corrupted diff' do
let(:corrupted_diff) do
with_empty_bare_repository do |repo|
content = File.read(Rails.root.join(
'spec/fixtures/encoding/Japanese.md').to_s)
commit_a = commit(repo, 'Japanese.md', content)
commit_b = commit(repo, 'Japanese.md',
content.sub('[TODO: Link]', '[現在作業中です: Link]'))
repo.diff(commit_a, commit_b).each_line.map(&:content).join
end
end
let(:cleaned_diff) do
corrupted_diff.dup.force_encoding('UTF-8')
.encode!('UTF-8', invalid: :replace, replace: '')
end
let(:encoded_diff) do
described_class.encode!(corrupted_diff.dup)
end
it 'does not corrupt data but remove invalid characters' do
expect(encoded_diff).to eq(cleaned_diff)
end
def commit(repo, path, content)
oid = repo.write(content, :blob)
index = repo.index
index.read_tree(repo.head.target.tree) unless repo.empty?
index.add(path: path, oid: oid, mode: 0100644)
Rugged::Commit.create(
repo,
tree: index.write_tree(repo),
message: "Update #{path}",
parents: repo.empty? ? [] : [repo.head.target].compact,
update_ref: 'HEAD'
)
end
end
end
describe '#encode_utf8' do

View File

@ -250,6 +250,14 @@ module TestEnv
"#{forked_repo_path}_bare"
end
def with_empty_bare_repository(name = nil)
path = Rails.root.join('tmp/tests', name || 'empty-bare-repository').to_s
yield(Rugged::Repository.init_at(path, :bare))
ensure
FileUtils.rm_rf(path)
end
private
def factory_repo_path