cmp different from the string representation
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- ruby
调研方向
阅读 ext/pathname/pathname.c 中的 cmp 实现以及 test/pathname/test_pathname.rb 中的相关用例,然后重现 issue 中所描述的 Pathname#<=> 与字符串排序结果之间的差异。完成的标准是确定预期的排序行为,并且相关测试或文档清楚地反映这一结论。
由索引模型根据 Issue 内容生成。
描述
There's an ordering difference when using the built-in <=> vs the string representation one:
> Pathname.new(File.expand_path('.')).glob('**/*.rb').sort.first(5)
=> [#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/chain.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/error_generator.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/expect_chain_chain.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/expectation_chain.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/message_chains.rb>]
> Pathname.new(File.expand_path('.')).glob('**/*.rb').sort_by(&:to_s).first(5)
=> [#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/chain.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/error_generator.rb>,
#<Pathname:/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/expect_chain_chain.rb>]
And the latter corresponds to the classic alternative:
> Dir[File.expand_path('**/*.rb')].sort.first(5)
=> ["/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks.rb",
"/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance.rb",
"/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/chain.rb",
"/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/error_generator.rb",
"/Users/pirj/source/rspec-dev/repos/rspec-mocks/lib/rspec/mocks/any_instance/expect_chain_chain.rb"]
Just by looking at the cmp implementation and tests I couldn't understand, is this the designed behaviour, or the behaviour is undefined?
Semantically, it would make sense to load rspec/mocks.rb first, and then rspec/mocks/any_instance.rb, not the other way around.
Some discussion in rspec-rails regarding the issues it may cause.
rspec-rails PR to change the helper template to use Pathname#glob instead of Dir.[].
A workaround rspec-rails plans to take is to sort_by(&:to_s) to get back to the string representation-like ordering.
(semi-)Related cops:
- 主要语言
- Ruby
- 星标
- 32
- 派生
- 24
- 平均合并
- 13 小时 2 分钟
- 30 天内合并 PR
- 1
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/pathname 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 55/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
Add puts 未关闭
难度 3/5 1-2 天 新手友好度 38/100
-
难度 2/5 1-3 小时 新手友好度 45/100
-
难度 5/5 一周以上 新手友好度 25/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 88/100
-
バグ
难度 1/5 1 小时以内 新手友好度 92/100
-
难度 2/5 1-3 小时 新手友好度 75/100
voxpupuli/puppet-epel#186 · 1 条评论 ·
-
external_created_at is no longer used for the message timestamp since the new message UI (v4.4.0) 未关闭Bug Frontend
难度 2/5 1-3 小时 新手友好度 78/100