Skip to content

Instantly share code, notes, and snippets.

@danii
Last active February 20, 2021 05:04
Show Gist options
  • Save danii/a58b3bcafa9faf1c3e4b01ad7495baf4 to your computer and use it in GitHub Desktop.
Save danii/a58b3bcafa9faf1c3e4b01ad7495baf4 to your computer and use it in GitHub Desktop.
Programmatic rust file splitter
mod::traits::iterator fn test_lt
mod fn test_multi_iter
mod::traits::iterator fn test_cmp_by
mod::traits::iterator fn test_partial_cmp_by
mod::traits::iterator fn test_eq_by
mod fn test_counter_from_iter
mod::adapters::chain fn test_iterator_chain
mod::adapters::chain fn test_iterator_chain_nth
mod::adapters::chain fn test_iterator_chain_nth_back
mod::adapters::chain fn test_iterator_chain_last
mod::adapters::chain fn test_iterator_chain_count
mod::adapters::chain fn test_iterator_chain_find
mod::adapters::chain fn test_iterator_chain_size_hint
mod::adapters::chain fn test_iterator_chain_unfused
mod::adapters::zip fn test_zip_nth
mod::adapters::zip fn test_zip_nth_side_effects
mod::adapters::zip fn test_zip_next_back_side_effects
mod::adapters::zip fn test_zip_nth_back_side_effects
mod::adapters::zip fn test_zip_next_back_side_effects_exhausted
mod::adapters::zip fn test_zip_nth_back_side_effects_exhausted
mod::adapters::step_by fn test_iterator_step_by
mod::adapters::step_by fn test_iterator_step_by_nth
mod::adapters::step_by fn test_iterator_step_by_nth_overflow
mod::adapters::step_by fn test_iterator_step_by_nth_try_fold
mod::adapters::step_by fn test_iterator_step_by_nth_back
mod::adapters::step_by fn test_iterator_step_by_nth_try_rfold
mod::adapters::step_by fn test_iterator_step_by_zero
mod::adapters::step_by fn test_iterator_step_by_size_hint
mod::adapters::filter_map fn test_filter_map
mod::adapters::filter_map fn test_filter_map_fold
mod::adapters::enumerate fn test_iterator_enumerate
mod::adapters::enumerate fn test_iterator_enumerate_nth
mod::adapters::enumerate fn test_iterator_enumerate_nth_back
mod::adapters::enumerate fn test_iterator_enumerate_count
mod::adapters::enumerate fn test_iterator_enumerate_fold
mod::adapters::filter fn test_iterator_filter_count
mod::adapters::filter fn test_iterator_filter_fold
mod::adapters::peekable fn test_iterator_peekable
mod::adapters::peekable fn test_iterator_peekable_count
mod::adapters::peekable fn test_iterator_peekable_nth
mod::adapters::peekable fn test_iterator_peekable_last
mod::adapters::peekable fn test_iterator_peekable_fold
mod::adapters::peekable fn test_iterator_peekable_rfold
mod::adapters::peekable fn test_iterator_peekable_next_if_eq
mod::adapters::peekable fn test_iterator_peekable_remember_peek_none_1
mod::adapters::peekable fn test_iterator_peekable_remember_peek_none_2
mod::adapters::peekable fn test_iterator_peekable_remember_peek_none_3
mod::adapters::take_while fn test_iterator_take_while
mod::adapters::skip_while fn test_iterator_skip_while
mod::adapters::skip_while fn test_iterator_skip_while_fold
mod::adapters::skip fn test_iterator_skip
mod::adapters::skip fn test_iterator_skip_doubleended
mod::adapters::skip fn test_iterator_skip_nth
mod::adapters::skip fn test_iterator_skip_count
mod::adapters::skip fn test_iterator_skip_last
mod::adapters::skip fn test_iterator_skip_fold
mod::adapters::take fn test_iterator_take
mod::adapters::take fn test_iterator_take_nth
mod::adapters::take fn test_iterator_take_nth_back
mod::adapters::take fn test_iterator_take_short
mod::adapters::scan fn test_iterator_scan
mod::adapters::flat_map fn test_iterator_flat_map
mod::adapters::flat_map fn test_iterator_flat_map_fold
mod::adapters::flatten fn test_iterator_flatten
mod::adapters::flatten fn test_iterator_flatten_fold
mod::adapters::inspect fn test_inspect
mod::adapters::inspect fn test_inspect_fold
mod::adapters::cycle fn test_cycle
mod::traits::iterator fn test_iterator_nth
mod::traits::iterator fn test_iterator_nth_back
mod::traits::double_ended fn test_iterator_rev_nth_back
mod::traits::double_ended fn test_iterator_rev_nth
mod::traits::iterator fn test_iterator_last
mod::traits::double_ended fn test_iterator_len
mod::traits::accum fn test_iterator_sum
mod::traits::accum fn test_iterator_sum_result
mod::traits::accum fn test_iterator_sum_option
mod::traits::accum fn test_iterator_product
mod::traits::accum fn test_iterator_product_result
mod::traits::accum fn test_iterator_product_option
mod::traits::iterator fn test_iterator_max
mod::traits::iterator fn test_iterator_min
mod::traits::iterator fn test_iterator_size_hint
mod::traits::collect fn test_collect
mod::traits::iterator fn test_all
mod::traits::iterator fn test_any
mod::traits::iterator fn test_find
mod::adapters::map fn test_find_map
mod::traits::iterator fn test_try_find
mod::traits::iterator fn test_try_find_api_usability
mod::traits::iterator fn test_position
mod::traits::iterator fn test_count
mod::traits::iterator fn test_max_by_key
mod::traits::iterator fn test_max_by
mod::traits::iterator fn test_min_by_key
mod::traits::iterator fn test_min_by
mod::traits::iterator fn test_by_ref
mod::traits::double_ended fn test_rev
mod::adapters::copied fn test_copied
mod::adapters::cloned fn test_cloned
mod::adapters::cloned fn test_cloned_side_effects
mod::traits::double_ended fn test_double_ended_map
mod::traits::double_ended fn test_double_ended_enumerate
mod::traits::double_ended fn test_double_ended_zip
mod::traits::double_ended fn test_double_ended_filter
mod::traits::double_ended fn test_double_ended_filter_map
mod::traits::double_ended fn test_double_ended_chain
mod::traits fn test_rposition
mod::traits fn test_rev_rposition
mod::traits fn test_rposition_panic
mod::traits::double_ended fn test_double_ended_flat_map
mod::traits::double_ended fn test_double_ended_flatten
mod::traits::double_ended fn test_double_ended_range
mod::range fn test_range
mod::range fn test_char_range
mod::range fn test_range_exhaustion
mod::range fn test_range_inclusive_exhaustion
mod::range fn test_range_nth
mod::range fn test_range_nth_back
mod::range fn test_range_from_nth
mod fn is_trusted_len
mod::range fn test_range_from_take
mod::range fn test_range_from_take_collect
mod::range fn test_range_inclusive_nth
mod::range fn test_range_inclusive_nth_back
mod::range fn test_range_len
mod::range fn test_range_inclusive_len
mod::range fn test_range_step
mod::adapters::step_by fn test_step_by_skip
mod::range fn test_range_inclusive_step
mod::range fn test_range_last_max
mod::range fn test_range_inclusive_last_max
mod::range fn test_range_min
mod::range fn test_range_inclusive_min
mod::range fn test_range_inclusive_folds
mod::range fn test_range_size_hint
mod::range fn test_range_inclusive_size_hint
mod::sources fn test_repeat
mod::sources fn test_repeat_take
mod::sources fn test_repeat_take_collect
mod::sources fn test_repeat_with
mod::sources fn test_repeat_with_take
mod::sources fn test_repeat_with_take_collect
mod::sources fn test_successors
mod::traits::marker fn test_fuse
mod::adapters::fuse fn test_fuse_nth
mod::adapters::fuse fn test_fuse_last
mod::adapters::fuse fn test_fuse_count
mod::adapters::fuse fn test_fuse_fold
mod::sources fn test_once
mod::sources fn test_once_with
mod::sources fn test_empty
mod::adapters::chain fn test_chain_fold
mod::adapters::step fn test_steps_between
mod::adapters::step fn test_step_forward
mod::adapters::step fn test_step_backward
mod::traits::double_ended fn test_rev_try_folds
mod::adapters::cloned fn test_cloned_try_folds
mod::adapters::chain fn test_chain_try_folds
mod::adapters::map fn test_map_try_folds
mod::adapters::filter fn test_filter_try_folds
mod::adapters::map fn test_filter_map_try_folds
mod::adapters::enumerate fn test_enumerate_try_folds
mod::adapters::peekable fn test_peek_try_folds
mod::adapters::skip_while fn test_skip_while_try_fold
mod::adapters::take_while fn test_take_while_folds
mod::adapters::skip fn test_skip_try_folds
mod::adapters::skip fn test_skip_nth_back
mod::adapters::take fn test_take_try_folds
mod::adapters::flat_map fn test_flat_map_try_folds
mod::adapters::flatten fn test_flatten_try_folds
mod fn test_functor_laws
mod fn test_monad_laws_left_identity
mod fn test_monad_laws_right_identity
mod fn test_monad_laws_associativity
mod::traits::iterator fn test_is_sorted
mod::traits::iterator fn test_partition
mod::adapters::peekable fn test_peekable_non_fused
mod::adapters::flatten fn test_flatten_non_fused_outer
mod::adapters::flatten fn test_flatten_non_fused_inner
mod::adapters::chain fn test_iterator_chain_advance_by
mod::adapters::chain fn test_iterator_chain_advance_back_by
mod::adapters::zip fn test_zip_cloned_sideffectful
mod::adapters::zip fn test_zip_map_sideffectful
mod::adapters::zip fn test_zip_map_rev_sideffectful
mod::adapters::zip fn test_zip_nested_sideffectful
mod::adapters::peekable fn test_iterator_peekable_mut
mod::traits::iterator fn test_iterator_advance_by
mod::traits::iterator fn test_iterator_advance_back_by
mod::traits::iterator fn test_iterator_rev_advance_by
mod::traits::iterator fn test_iterator_rev_advance_back_by
mod::adapters::flatten fn test_flatten_non_fused_inner
mod::adapters::intersperse fn test_intersperse
mod::adapters::intersperse fn test_intersperse_size_hint
mod::adapters::intersperse fn test_fold_specialization_intersperse
mod::adapters::intersperse fn test_try_fold_specialization_intersperse_ok
mod::adapters::intersperse fn test_try_fold_specialization_intersperse_err
#!/bin/python3
def parse(file: str):
result = []
pos = 0
while True:
fn_pos = file.find("fn ", pos)
fn_start = fn_pos
if fn_pos == -1:
result.append(file[pos:])
break
other = file[pos:fn_start]
if other.endswith("#[test]\n"):
fn_start -= 8
other = other[-1][:-8]
fn_arg_start_pos = file.find("(", fn_pos)
fn_arg_end_pos = file.find(")", fn_pos)
fn_start_pos = file.find("{", fn_arg_end_pos)
fn_name = file[fn_pos + 3:fn_arg_start_pos]
parens = 0
pos = fn_start_pos + 1
while True:
paren_open_pos = file.find("{", pos)
paren_close_pos = file.find("}", pos)
if paren_open_pos < paren_close_pos and paren_open_pos != -1:
parens += 1
pos = paren_open_pos + 1
else:
pos = paren_close_pos + 1
parens -= 1
if parens == -1:
break
fn_content = file[fn_start:pos]
result.append(other)
result.append((fn_name, fn_content))
return result
def main():
read_data = None
with open("./iter_backup.rs") as file:
read_data = parse(file.read())
split_data = dict()
with open("./fns.txt") as file:
for line in file.readlines():
line = line.split(" ")
fn_name = line[-1][:-1]
tags = line[:-2]
split_data[fn_name] = None if len(tags) == 0 else tags[0]
files = dict()
for data in read_data:
if isinstance(data, str):
file = files.get("mod", "")
file += data
files["mod"] = file
else:
alias = split_data.get(data[0]) or "mod"
file = files.get(alias, "")
file += data[1]
files[alias] = file
for name, content in files.items():
print(name)
with open(f"./library/core/tests/iter/{name}.rs", "w+") as file:
file.write(content)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment